Seydina's avatar

How can we change submit button styles if disabled or if not disabled?

Hello,

<button class="inline-flex items-center px-6 py-2 bg-gray-300 border border-transparent rounded-md font-bold text-gray-400 tracking-widest" 
   type="submit" {{ (!is_null($picture)  &&  !empty($picture))  ?  ' '  :  'disabled' }}>
    Save
  </button>

This code give me a button with grayed background and what I want to achieve is to give blue background when submit button is enabled. I check if picture variable is not null and not empty to disable submit button or enable it. That works well but I want to change background color and others styles when the submit button is active (that's to say when $picture variable is not null and not empty). Should I use conditional Alpine JS class :class and if so, how to do it?

0 likes
6 replies
Bogey's avatar

Just use the same code you are using for disabeling the button just inside the styles attribute and the actual class names in the other condition. Or am I missunderstanding you?

Bogey's avatar
Bogey
Best Answer
Level 1

@Seydina

<button class="inline-flex items-center px-6 py-2 {{ (!is_null($picture)  &&  !empty($picture))  ?  'bg-blue-300 text-green-400'  :  'bg-gray-300 text-gray-400' }} border border-transparent rounded-md font-bold tracking-widest" 
   type="submit" {{ (!is_null($picture)  &&  !empty($picture))  ?  ' '  :  'disabled' }}>
    Save
  </button>
Seydina's avatar

@Bogey It works thanks but for simplicity I prefer now :disabled tailwind prefix solution from @snapey

Please or to participate in this conversation.