I have the following button in my view:
<button type="button" class="btn btn-lg btn-primary">Primary button</button>
I want to add the disabled property to it if and only a certain condition is true. How do I this in an elegant way?
You could use the rails helper button_tag with a boolean check
<%= button_tag "Primary button", class: 'btn btn-lg btn-primary',
disabled: condition_check_method %>
You Should do this two or more way:
<button type="button" class="your-class btn btn-lg btn-primary">Primary button</button>
<script type="text/javascript">
$(function(){
if(Condition){
$('.your-class').addClass('disabled');
}
});
</script>
OR
In The rails term
<button type="button" class="btn btn-lg btn-primary <%= conditon ? "disabled" : ""%>">Primary button</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With