I'm trying to enable disabled button after I load a table on the page.
self.uploadPdfButtonIsEnabled = false;
self.pricingTableRenderedHandler = function (data, stateName) {
self.uploadPdfButtonIsEnabled = true;
//some other irrelevant logic
}
.cshtml file
<button id="uploadPdfsButton" data-bind="click: $root.openPdfUpload, enable: uploadPdfButtonIsEnabled">
<span >Upload PDF</span>
</button>
As a result, I only get this button disabled and it is not enabled. Tried to debug and the pricingTableRenderedHandler is entered, uploadPdfButtonIsEnabled becomes true but the button is still disabled
CodePudding user response:
You have to use an observable for the knockout binding to be able to update automatically:
// Pass the initial value: `false`
self.uploadPdfButtonIsEnabled = ko.observable(false);
self.pricingTableRenderedHandler = function (data, stateName) {
// Update by calling with the new value: `true`
self.uploadPdfButtonIsEnabled(true);
}