You’ll have to replace the onClick handler for the RemoveRow button.
//get the remove Button Model
var button = CAF.model("jsf:defaultForm:zzz1:__rowid0:removeRowButton");
//store the current onclick
var _onclick = button.element.onclick;
//create your custom onClick
button.element.onclick = function() {
//todo add your validation function
//delegate to the original onclick
_onclick();
};
In every row, you probably have a remove row button, correct?
If so, just add a ScriptBlock in every row, and in the script block you’ll have javascript like the sample above, but dynamically looking up each row:
//get the remove Button Model
var button = CAF.model("#{caf:cid('removeRowButton')}");
//store the current onclick
var _onclick = button.element.onclick;
//create your custom onClick
button.element.onclick = function() {
//todo add your validation function
alert("hello");
//delegate to the original onclick
_onclick();
};
Following your suggestion I have inserted a Script Blockinside a Remove Row Iconin the row with the following code:
//get the remove Button Model
var button = CAF.model("#{caf:cid('defaultForm:removeRowIcon')}");
//store the current onclick
var _onclick = button.element.onclick;
//custom onClick
//based on the result of the confirm() dialog.
button.element.onclick = function() {
if (confirm("really delete?")) _onclick(); else return(false);
};
This way the row is not deleted if Cancel is pressed.