PDA

View Full Version : Set a field to null???



Gamer
27 Jan 2011, 9:22 AM
I have code to validate a custom field I'm making


//check to make sure first number is lower
if (this.ownerCt.prefix.getValue() > suffix.newValue){
this.ownerCt.prefix.setMinValue(oldValue);
}
//check to make sure second number is higher
if(this.ownerCt.suffix.getValue() < prefix.newValue){
this.ownerCt.suffix.setMaxValue(oldValue);
}

After validating the inputs, if the user has input an incorrect value, I want to reset the field to a null value.
How would I go about doing that, also would that code go in with the validation or into another area? Please be as specific and detailed as possible I'm still very new to the extjs library. Any help is appreciated.
Thanks!!!

Gamer
27 Jan 2011, 8:06 PM
bump

dduffy
28 Jan 2011, 3:13 AM
Can you not just use Ext.form.Field.setValue()? found @ following URL:

http://dev.sencha.com/deploy/dev/docs/output/Ext.form.Field.html

Gamer
28 Jan 2011, 7:12 AM
When I try to add something like


this.prefix.setValue(null);

which I believe should work, my field doesn't reset to null. I've also tried a couple of other things but I'm pretty sure that using the above the code should set my fields to null when I hit the submit button. Unless I'm need to insert that code in another area. I've included a link to my test page if that can help to solve the problem.
http://www.carterbillboards.com/ext-3.2.0/examples/ngamer/custome_test.html

dduffy
28 Jan 2011, 7:28 AM
this works for me.

var x = Ext.getCmp("suffix");
x.setValue("");

Gamer
28 Jan 2011, 8:18 AM
So my new code looks like this....


if(this.ownerCt.suffix.getValue() < prefix.newValue){
this.ownerCt.suffix.setMaxValue(oldValue);
var x = Ext.getCmp("suffix");
x.setValue("");
return;
}

I also have my test page updated to that. It worked for a second, but now it's not working anymore. Also for the second that it was working, it only worked for the "suffix" field and I wasn't able to duplicate it for the "prefix" field. Why would it work one way and not the other? I really appreciate all the help.

dduffy
28 Jan 2011, 8:23 AM
personnelly i would not write the code the way you are, I would have an on blur event to manage this, or send the command to the server side and let the server side indicate the issue and return the response to the form. You will have to test on the server side any way for security, as a user could just post to your server side and ignore client side validation.

valititi
28 Jan 2011, 8:48 AM
I saw your form js code...
1. in the handler function try to put some alert on some error events (name not correct etc...) on successful, no alerts, but on errors yes
2. your handler must RETURN if errors, and, so, not submitting the form...

Gamer
1 Feb 2011, 1:04 PM
Well I changed it to use an onBlur event


onBlur: function(field, newValue, oldValue) {
this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
this.hiddenField.dom.value = this.getValue();

//check to make sure the first number is lower
if (this.ownerCt.prefix.getValue() > suffix.newValue){
this.ownerCt.prefix.setMinValue(oldValue);
var y = Ext.getCmp("prefix");
this.y.setValue("")
return;
}

//check to make sure second number is higher
if(this.ownerCt.suffix.getValue() < prefix.newValue){
this.ownerCt.suffix.setMaxValue(oldValue);
var x = Ext.getCmp("suffix");
this.x.setValue("");
return;
}
},


but I'm still kind of confused about how blur works exactly, my test page at the top is updated with this being added in so any help is again appreciated.

dduffy
1 Feb 2011, 2:23 PM
confused by onBlur - I suggest reading a bit about JS, following is a suggested reading book by Douglas Crockford.
http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742

Gamer
3 Feb 2011, 6:34 AM
I am not really confused by onBlur, I understand what it does. I am having trouble though with getting my test page to work the way I want. The help dduffy gave me worked for a little bit, but it is not working anymore for some reason. I still do need the page to work correctly and still need help with this. So any advice is appreciated.