JQuery - Warum unterstützt die Validierungsregel den vordefinierten Wert nicht?Jquery

JQuery-Programmierung
Anonymous
 JQuery - Warum unterstützt die Validierungsregel den vordefinierten Wert nicht?

Post by Anonymous »

Ich habe zwei jQuery -Validierungsfunktionen wie folgt definiert: < /p>




Test




/////////////////////////////////////////////////////
function LessThanValidator(event)
{
var lowID = event.data.lowID;
var highID = event.data.highID;
var formID = event.data.formID;
var lowValue = parseInt( $(lowID).val() );
//var lowValue = parseInt( $(lowID).attr("value") ); // this doesn't fix

if ( isNaN(lowValue) ) {
lowValue = 0;
}

$(highID).rules('remove', 'min');
$(highID).rules('add', { min: lowValue });
$(formID).validate().element( highID );

return false;
}

function LargerThanValidator(event)
{
var lowID = event.data.lowID;
var highID = event.data.highID;
var formID = event.data.formID;
var highValue = parseInt( $(highID).val() );
//var highValue = parseInt( $(highID).attr("value") ); // this doesn't fix

if ( isNaN(highValue) ) {
highValue = 0;
}

$(lowID).rules('remove', 'max');
$(lowID).rules('add', { max: highValue });
$(formID).validate().element( lowID );

return false;
}

$(document).ready( function() {

// validate the #regFormBody form when it is submitted
$("#regFormBody").validate({
debug: true,
errorPlacement: function(error, element) {
error.insertAfter( element.parent() );
},
rules: {
confeelow: { required: true, digits: true, maxlength: 10, max: isNaN(parseInt($("#confeehigh"))) ? 0 : parseInt($("#confeehigh")) },
confeehigh: { required: true, digits: true, maxlength: 10, min: isNaN(parseInt($("#confeelow"))) ? 0 : parseInt($("#confeelow")) }
},

messages: {
confeelow: { max: "Please enter a value less than or equal to To (US$)" },
confeehigh: { min: "Please enter a value greater than or equal to From (US$)" }
}
});

///////////////////////////////////////////////////////////////
$("#confeelow").bind("change", {lowID: "#confeelow", highID: "#confeehigh", formID: "#regFormBody"}, LessThanValidator);
$("#confeehigh").bind("change", {lowID: "#confeelow", highID: "#confeehigh", formID: "#regFormBody"}, LargerThanValidator);
});



.error
{
color:red;
}








Desired Consulting Fee From (US$) *



To (US$) *












< /code>

Ich verwende im Grunde die obigen Funktionen, um sicherzustellen $("#confeelow").bind("change", { lowID: "#confeelow", highID: "#confeehigh", formID: "#profileFormBody" }, LessThanValidator);
$("#confeehigh").bind("change", { lowID: "#confeelow", highID: "#confeehigh", formID: "#profileFormBody" }, LargerThanValidator);
< /code>

Diese beiden Funktionen funktionieren ziemlich gut. Wenn ich jedoch die Werte für #ConFeHigh und #Confeelow vordefiniere, können diese Felder den Validierungstest nicht bestehen. Ich kann wirklich nicht herausfinden, warum. Da diese Validierungsfunktionen ohne vorpopulierte Werte gut funktionieren.

< /code>

Mit anderen Worten, wenn ich manuell 12 für RefeElow und 23 für Konfigurierungen eingehe, funktioniert die Validierung gut.

< /code>

Kann mir jemand einige Hinweise geben, warum es für vordefinierten Wert nicht funktioniert?///////////////// Update-001 ////////////////////
< /code>

Einige Personen haben möglicherweise diese Frage für mich: Warum Sie einen Standardwert verwenden müssen, wenn der Code mit neuen eingegebenen Daten funktioniert. Hier ist Grund < /p>

1> First the user will be allowed to enter data
2> Second the user will submit the form and store in DB
3> When next time the user logins again

I have to repopulate the text field by using some code similar as follows:

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post