mardi 24 février 2015

before button onclick spring form submission validate the form

enter image description here


Image show the validation properly, when i click on save button it validate that glElement selected twice or duplicate simulataneously it submit the form what i want befor submission of form the form validate


below is my code and approach ==========================================



<div id="preacq" class="MICss">
<div id="linkopen">
<div class="span5">
<label class="abc" style="margin-bottom: 1px;"> <spring:message
code="MinorityInterest.elementName" /></label>
<form:select id="glListName0" path="glElementId"
name="glListName[]" class="input-block-level" size="1" multiple="bbn">
</form:select>
</div>

<div class="span5">
<label class="abc" style="margin-bottom: 1px;"> <spring:message
code="MinorityInterest.AccountType" /></label>
<form:select path="accountType" id="accountName0"
name="accountName" class="input-block-level" multiple="bbn">
<option value="0">select</option>
<option value="1">Debit</option>
<option value="2">Credit</option>
</form:select>
</div>

<div class="span5">

<label class="abc" style="margin-bottom: 1px;"><spring:message
code="MinorityInterest.preAcq" /></label> <input type="text"
name="preAcqSurPlus" id="preacqas0" class="input-block-level abc"
path="preAcqSurPlus" onblur="checkPreAmount(this.id)"></input>
</div>

<div class="span5">
<label class="abc" style="margin-bottom: 1px;"> <spring:message
code="MinorityInterest.Share" /></label> <input type="text"
name="Shares" id="share0" path="Shares" class="input-block-level abc"></input>
</div>

<div class="span2" style="margin-top: 15px;">
<div class="add_remove">
<a><img onclick="addMore(this)"
src="<%=Config.getStaticURL()%>resources/img/Add-field.png" /></a>
</div>
<div class="add_remove">
<a><img onclick="removeMI(this)" src= "<%=Config.getStaticURL()%>resources/img/remove-field.png" /></a>
</div>
</div>
</div>

<script type="text/javascript">
function addMore(btn) {

alert("adddiv"+btn);
var source = $(btn).closest(".MICss");
cloned = source.clone();
cloneCount = 0;
cloned.hide().insertAfter(source).slideDown(200);
$('.MICss[id^=preacq]').each(function(){
$(this).attr('id', 'preacq'+cloneCount);
$.each($(this).find('*[id]'), function(){
var id = $(this).attr('id').replace(/[0-9]/g,'');
$(this).attr('id', id+cloneCount);
});
cloneCount++;
});
}

</script>

<script>

function removeMI(btn){

// $($(btn).data('parent-id')).remove();
if($('.MICss[id^=preacq]').length <= 1){
alert("No more textbox to remove");
return false;
}
$(btn).closest(".MICss").slideUp(200, function(){
$(this).remove();
});
}
</script>
</div>
</div>
<div class="span5" style="float: left;width:38%">
<label class="abc" style="margin-bottom: 1px; margin-top:67px; font-size: 17px; margin-left: 347px;"> <spring:message
code="MinorityInterest.TotalAmount" /></label>
</div>

<div class="span5" style="float: right;">
<input type="text" style="margin-top: 67px;margin-left: -135px;width: 211px;">
</div>
<div class="span5" style="float: right;">
<input type="text" style="margin-top:67px;margin-left: -158px;width: 211px;">
</div>
<form:hidden path="parenCompanyId" id="PcId"/>
<form:hidden path="childCompanyId" id="CcId"/>
<form:hidden path="financialYearId" id="FyId"/>
<form:hidden path="reportingPeriodId" id="rPId"/>
<div class="span6" style="float: right; margin-right: 0%">
<!-- <input id="saveMI" class="" type="button" value="Save" onclick="saveMI();"> -->
<button id="saveButtonId" name="save" value="save" onclick="saveMI();"
style="height: 30px; width: 50px;position: fixed; top: 627px;">save</button>
</div>

</form:form>


my jsfile=======================my approach==================


/** * * * * @author Vaibhav * for form submission */



function saveMI(){

$("#cmpCombo").val();
$("#parentCmp").val();
$("#financialYearId").val();
$("#reportingPeriodId").val();


$('#PcId').val($("#cmpCombo").val());
$('#CcId').val($("#parentCmp").val());
$('#FyId').val($("#financialYearId").val());
$('#rPId').val($("#reportingPeriodId").val());


/* this is gl element validation logic if duplicatye element is selected*/
for ( var index = 0; index <= cloneCount; index++) {

var contains = (removecnt.indexOf(index) > -1);
elementId = $("#glListName" + index).val();
for ( var k = 0; k <= cloneCount; k++) {
if (k == index)
continue;
else {
if ($("#glListName" + k)
.val() == elementId
&& contains == false) {
alert("gl mein gya");
$("#addElementTotal"+ (index - 1));
$("#glListName" + k).addClass("field-error");
$("#amountError").hide();
$('#selectOtherElementError').show();
return false;
}
else{
alert("vaibhav");
$("#minorityForm").submit();
}
}
}
}
}

Aucun commentaire:

Enregistrer un commentaire