The .click in jquery is deprecated. So I made amendments to the existing code, however, there seems to be some issue.
GetPageButtons() {
let $saveButton = $("<input />", {
type: "button",
value: "Save",
class: "button large save",
}),
$cancelButton = $("<input />", {
type: "button",
value: "Cancel",
class: "button large cancel",
});
$saveButton.click(() => {
this.UpdateRecord();
});
$cancelButton.click(() => {
this.modal.success = true;
let _parent = this;
$.each(_parent.fields, function (i, field) {
delete this.newValue;
this.element.val("");
});
});
return [$cancelButton, $saveButton];
}
The above code works, although my linter complains saying it deprecated.
GetPageButtons() {
let $saveButton = $("<input />", {
type: "button",
value: "Save",
class: "button large save",
}),
$cancelButton = $("<input />", {
type: "button",
value: "Cancel",
class: "button large cancel",
});
$saveButton.on("click", function() {
this.UpdateRecord();
});
$cancelButton.on("click", function() {
this.modal.success = true;
let _parent = this;
$.each(_parent.fields, function (i, field) {
delete this.newValue;
$( this ).element.val("");
});
});
return [$cancelButton, $saveButton];
}
The refactor to the suggested use of .on('click', fn){} however is not functioning. I get an error that says:
"Uncaught TypeError: this.UpdateRecord is not a function".
Why? It should work the same as the .click which is shorthand for .on. Any suggestions???