I am using jquery to create a pop dialog in a page. The user is entering some text in the dialog inputs and based on this I am calling to a servlet. The thing is that somehow, I can’t get the inputs content everytime. I am trying to also get the change event for the input and when is not working, is not even triggering the events, but like I said, not sure why sometimes is not working. After calling the servlet and returning it works as expected, it only fails the first time (and not always).
This is my code JS:
$(function()
{
//$.fn.bootstrapBtn = $.fn.button.noConflict();
document.body.style.cursor = 'default';
var dialog, form, product= $( "#product"), documentType= $( "#documentType"), docId = $( "#docId"), description= $( "#description"), docNameWithSpace = $("#docNameWithSpace"), name = $("#name"), documentTypeId = $( "#documentTypeId" ), projectTrackerPrefix = $ ("#projectTrackerPrefix"), allFields = $( [] ).add( projectTrackerPrefix, documentTypeId, product, documentType, name, description, docNameWithSpace);
dialog = $( "#dialog-form" ).dialog(
{
autoOpen: false,
height: 400,
width: 480,
modal: true,
buttons: {
"Create Document": createDocument,
Cancel: function() {
dialog.dialog( "close" );
}
},
close: function() {
form[ 0 ].reset();
document.getElementById("dialogForm").reset();
$("#spaces option:selected").each(function () {
$(this).removeAttr('selected');
});
allFields.removeClass( "ui-state-error" );
}
});
form = dialog.find( "form" ).on( "submit", function( event )
{
event.preventDefault();
createDocument();
return true;
});
function createDocument()
{
var title = description.val();
var result= checkValidChars(document.getElementById("description").value);
if(!result)
{
document.body.style.cursor = 'wait';
document.getElementById("docTitle").value=document.getElementById("description").value;
var var1 = document.getElementById("description").value;
var var2 = document.getElementById("docTitle").value;
alert("1->"+var1);
alert("2->"+var2);
document.getElementById("removeOutgoingLinks").value = ""+document.getElementById("removeOutgoingLinksCheck").checked;
document.getElementById("keepRelativeLinks").value = ""+document.getElementById("keepRelativeLinksCheck").checked;
$("#createDocForm").submit();
}
}
});
This is the HTML one:
<div id="dialog-form" title="Create New Document">
<form id="dialogForm">
<fieldset>
<input type="hidden" name="product" id="product" value="" class="text" style="color: -internal-light-dark-color(rgb(84, 84, 84), rgb(170, 170, 170)) !important; background-color: -internal-light-dark-color(rgb(235, 235, 228), rgb(45, 45, 45)) !important;" disabled="disabled">
<input type="hidden" name="documentType" id="documentType" value="" class="text" style="color: -internal-light-dark-color(rgb(84, 84, 84), rgb(170, 170, 170)) !important; background-color: -internal-light-dark-color(rgb(235, 235, 228), rgb(45, 45, 45)) !important;" disabled="disabled">
<input type="hidden" name="docId" id="docId" value="" class="text" style="color: -internal-light-dark-color(rgb(84, 84, 84), rgb(170, 170, 170)) !important; background-color: -internal-light-dark-color(rgb(235, 235, 228), rgb(45, 45, 45)) !important;" disabled="disabled">
<input type="hidden" name="documentTypeId" id="documentTypeId" value="" class="text" style="color: -internal-light-dark-color(rgb(84, 84, 84), rgb(170, 170, 170)) !important; background-color: -internal-light-dark-color(rgb(235, 235, 228), rgb(45, 45, 45)) !important;" disabled="disabled">
<input type="hidden" name="projectTrackerPrefix" id="projectTrackerPrefix" value="$currProject.getTrackerPrefix()" class="text" style="color: -internal-light-dark-color(rgb(84, 84, 84), rgb(170, 170, 170)) !important; background-color: -internal-light-dark-color(rgb(235, 235, 228), rgb(45, 45, 45)) !important;" disabled="disabled">
<label for="id">Selected Documents</label>
<textarea type="text" name="selectedDocs" id="selectedDocs" value="" class="text" style="color: -internal-light-dark-color(rgb(84, 84, 84), rgb(170, 170, 170)) !important; background-color: -internal-light-dark-color(rgb(235, 235, 228), rgb(45, 45, 45)) !important; width: 95%; padding: .4em; height:100px;" disabled="disabled"/>
<label for="id">Description</label>
<input type="text" name="description" id="description" class="text">
<label for="removeOutgoingLinksCheck">Remove Outgoing Links from Document</label>
<input type="checkbox" name="removeOutgoingLinksCheck" id="removeOutgoingLinksCheck">
<label for="keepRelativeLinksCheck">Keep relative Work Item links between reused Documents</label>
<input type="checkbox" name="keepRelativeLinksCheck" id="keepRelativeLinksCheck" checked="checked">
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</form>
</div>
Sometimes it works the first time, sometime it doesn’t. After returning from the servlet is always working. I have even tried to add onchange events and also
$("#description").on("input",function(e) { but they are not being reached, meaning that somehow is consistent in not detecting the changes, however, the user is entering text….