Edit: Here is a JSFiddle which displays the problem I'm having:
http://jsfiddle.net/gyhvpmgy/4/
I have the following function creating a dynamic div:
InvalidField.prototype.getMessageStructure = function(){
var div = $('<div></div>').addClass('invalidRow');
var span = $('<span></span>')
.text(this._message)
var button = $('<button></button>')
.addClass('btn_AlertFocus')
.text("Go To Field")
.data("field", this._field[0].name)
return div.append(button).append(span);
};
Prior to the return line, through debugging I can see that button.data('field') contains, as it should: "applicant.email".
I also have the following generic button click event:
$(document).on('click', '.btn_AlertFocus', function() {
var field = $(this).data('field');
goToFieldFromAlert('input[name="' + field + '"]');
});
'field' is now coming up as undefined.
Is anyone able to tell me why, it will probably be something obvious - this is a new feature to me?
Below is the snippet that takes this returned string value.
function validateForm(){
if(list_Invalid.size() > 0){
var structure = "";
for ( i = 0; i < list_Invalid.size(); i ++){
structure += list_Invalid.item(i).getMessageStructure()[0].outerHTML;
}
var alert = new Alert(structure,
function(){
}
).showAlert();
return false;
}
return true;
}
Many thanks!