Reputation: 11
I have a button called customer-delete
and it should be disabled when customer has some information and should be enabled if customer has no such information.
my code is like this:
if(customer.name!=null && customer.email!=null){
$("#customer-delete").button("disable");
console.info("disabled");
}else{
$("#customer-delete").button("enable");
console.info("enabled");
}
but this is not working properly. console displays it correctly so that means there is no problem with the logic, but the button is always enabled.
Can anyone give me a solution for this?
Upvotes: 1
Views: 542
Reputation: 51201
Use .prop()
$("#customer-delete").prop("disabled",true);
and .removeProp()
$("#customer-delete").prop("disabled",true);
// is the same as:
$("#customer-delete").removeProp("disabled");
prior to jQuery version 1.6, use .attr()
.
Or when working with jQuery UI you can hand this over as parameter-object:
$("#customer-delete").button({ disabled: true });
or after the initialisation with the setter-method:
$("#customer-delete").button( "option", "disabled", true );
EDIT:
I'm sorry for ignoring the jquery-mobile
tag. According to the docs your try .button("disable")
is correct. Now there are several possibilities:
The doc states the following - I cannot judge from the context you gave, whether this is the case for you.
The following methods apply only to form buttons. Link-based buttons do not have any associated methods.
Your selector does not match correctly.
Conflicts elsewhere in your code.
Upvotes: 2
Reputation: 175776
If it has a data-role of button but is not actually a button (a link for example) you can't use those features instead;'
$("#customer-delete").addClass('ui-disabled');
Upvotes: 0
Reputation: 13800
From the documentation, is it not supposed to look like this?
$( "#customer-delete" ).button({ disabled: true });
Upvotes: 0
Reputation: 8919
Try this
if(customer.name!=null && customer.email!=null){
$("#customer-delete").attr("disabled", true);
}else{
$("#customer-delete").attr("disabled", false);
}
Upvotes: 0
Reputation: 1406
if(customer.name!=null && customer.email!=null){
$("#customer-delete").attr("disabled", "disabled");
console.info("disabled");
}else{
$("#customer-delete").removeAttr("disabled");
console.info("enabled");
}
Upvotes: 0