I have created this small 'modal'-form using bootstrap which looks a bit as follows:
<div class="modal fade" tabindex="-1" role="dialog" aria- labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="H1">Create new Workflow</h4>
</div>
<div class="modal-body">
<ul class="list-group">
....
<li class="list-group-itemCustom">
<input type="text" id="txtWorkflowAdmin" />
</li>
...
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" id="BtnSave" class="btn btn-primary">Save</button>
</div>
</div>
</div>
The modals are stored in a separate aspx-page. I retrieve the modals using a ajax-call after which i bind the event-handlers:
function LoadModals() {
$.ajax({
type: "GET",
url: "Modalforms.aspx",
success: function (data) {
$("#Divmodals").html(data);
SetModalEventtriggers();
},
error: function (xhr, errStatus, thrownError) {
LogException(errStatus, thrownError, "LoadModals", []);
}
})
}
function SetModalEventtriggers() {
$("#txtWorkflowAdmin").blur(function () {
CheckAdmin($(this));
})
$("#BtnSave").click(function () {
SaveWorkflow();
})
}
Those 2 events work perfectly independent. Example When i click the button (BtnSave
) without txtWorkflowAdmin
is focussed then the function SaveWorkflow
gets executed.
Yet when my txtWorkflowAdmin
is focussed and i click BtnSave
. Then .Click Function
isn't fired. The function of the OnBlur
get executed though. When i click a second time on BtnSave
then the SaveWorkflow
is executed.
Why does this behavior occur? Am I missing some basic knowledge about Javascript-events?
The Functions (Basic code supplied: errorhandling deeper code not included) :
function SaveNewWorkflow() {
... (Check if other fields are filled in
if (!CheckValidityUsername($("#txtWorkflowAdmin").val())) {
$("#WorkflowAdminErrorMessage").css("display", "block");
return;
}
... (If all fields are filled in => This piece of code is never reached when txtWorkflowAdmin is focussed)
$.ajax({
type: "POST",
url: "Actions.aspx",
data: outerJsonData,
success: function () {
... Do some actions here.
}})
}
function CheckAdmin(txtAdmin) {
// Show/Hide errormessage
if (!CheckValidityUsername(txtAdmin.val())) {
btnClicked.closest("li").prev().css("display", "block");
}
else {
btnClicked.closest("li").prev().css("display", "none");
}
}
function CheckValidityUsername(userName) {
var validUser = true;
var jsonData = { action: "CheckUsername",
SidUser: userName,
Docbase: docbase
};
$.ajax({
type: "GET",
async: false,
url: "Search.aspx",
data: jsonData,
success: function (data) {
var obj = jQuery.parseJSON(data);
validUser = obj.ValidUser;
return validUser;
},
error: function (xhr, errStatus, thrownError) {
LogException(errStatus, thrownError, "CheckValidityUsername", jsonData);
}
})
return validUser;
}
Thanx to anyone who was helping me! Thanks to you guys, the problem was quickly resolved!