Make disabled a prop of the component. And move your logic inside the component.
Sep 24, 2021
4
Level 13
disable blade button
I need to disable an x-button blade component based on a condition. On a normal button I do it like this:
<button type="submit" class="mb-2 mr-2 text-black" {{ ($disabled) ? ' disabled' : '' }}>CAPTION</button>
When I change this to use the x-button component:
<x-button type="submit" class="..." {{ ($disabled) ? ' disabled' : '' }}>CAPTION</x-button>
it doesn't work but throws: syntax error, unexpected token "endif"
The components/button.blade.php is very simple
<button {{ $attributes->merge(['type' => 'submit', 'class' => '...']) }}>{{ $slot }}</button>
Obviously the blade component does not use the disabled global attribute, even if i call it like
<x-button type="submit" class="..." disabled>CAPTION</x-button>
this will not work as expected but renders to
<button type="submit" class="..." disabled="disabled">Equip</button>
Can someone give me a hint how to change the component so that I can apply the "disabled" global attribute to the button element? Thx Marco
Level 51
1 like
Please or to participate in this conversation.