Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread
Author: Subject: How to work with array of form elements?
Hollstar
Member

Posts: 11
Registered: 4/4/2008
Location: Australia
Member Is Offline
posted on 4/4/2008 at 10:43 PM Reply With Quote
How to work with array of form elements?


Hi All,

It would seem that Tigra Form Validator does not support an array of form elements such as an array of Text boxes?

My current problem is this: Using some AJAX, the page/form is dynamically updated based on the selection of a drop down box.

This updates a series of text boxes used to enter price information. These text boxes relate directly to a quantity for the selected product in question.

Due to the dynamic nature, I can't simply hard code this into the validator as the text boxes may not always exist...

Any suggestions on how I can get around this?

My only thought was to detect when the validator had finished running (successfully or not), and then run a seperate script to check the array....... I couldn't however figure out how to do this! :(
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 4/5/2008 at 04:49 AM Reply With Quote

In the static samples the validator object is initialized with the configuration variables at the time the page loads.
In your case you can dynamically generate the configuration variable based on existing form fields and initialize the validator with it just prior to executing the validation (.exec() call).
View User's Profile View All Posts By User U2U Member
Hollstar
Member

Posts: 11
Registered: 4/4/2008
Location: Australia
Member Is Offline
posted on 4/5/2008 at 08:41 AM Reply With Quote

Hi Mate,

Thanks for the reply... I'm not sure we are on the same page which I suspect was due to my poor explaination?

Using the drop down box on the page and some AJAX, I'm dynamically changing several text boxes on the page.
The problem is the number of boxes and their 'name' will change with every change you make using the drop down box.

Are you suggesting using JavaScript I change the configuration at the bottom of the page each and every time I use my AJAX?
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 4/5/2008 at 02:29 PM Reply With Quote

The configuration at the bottom of the samples is a javascript code. The approach in your case would be to generate it in the browser right before the form needs validation. You don't need to re-generate it after each ajax request, just once before you need it.

initially you start with empty array or with array listing the static inputs:

var a_fields = {
};

this part is static in the text of the HTML document.
Then say you learned that there is new input box added to the form:

a_fields['email'] = {'l':'E-mail','r':true,'f':'email','t':'t_email'};

you call this from the event handler that processes the results of ajax call.
View User's Profile View All Posts By User U2U Member
Hollstar
Member

Posts: 11
Registered: 4/4/2008
Location: Australia
Member Is Offline
posted on 4/6/2008 at 09:41 AM Reply With Quote

Thanks again Tigra, appreciate your help!
The only problem I now have is that regardless if you run the validator constructor after updating the fields with the AJAX, it still looks for some of the old fields which no longer exist?

I thought by running it again, or at the time the Submit button is pressed, it checks the fields again...

Am I wrong?
View User's Profile View All Posts By User U2U Member
Hollstar
Member

Posts: 11
Registered: 4/4/2008
Location: Australia
Member Is Offline
posted on 4/8/2008 at 09:15 AM Reply With Quote

So, Tigra... Can I assume from your silence you can't run the constructor again once adding new form elements to the array?

My solution to this problem was to delete the elements from the array that were added in the AJAX script... This means you don't have to worry about this constructor rubbish! :)
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 4/9/2008 at 12:39 AM Reply With Quote

You can create new validator object with new configuration structure. If validator looks for old fields then it means that you either use old validator instance or you feed new validator old configuration structure.
View User's Profile View All Posts By User U2U Member
Post new thread

Related Links:
Product Page Tigra Form Validator
Product Demonstrations Product Demos
Registration Form Validation
Login Form Validation
Free Download Free Download
Product Documentation Documentation
Documenation Page
Change Log
Validators Comparison Table
Support Forum Support Forum
 
Tigra Form Validator PRO
Product Demonstrations Product Demos
Registration Form Validation
Login Form Validation
Multiple Forms Validation
Product Documentation Documentation
Documenation Page
Change Log
Validators Comparison Table
Support Forum Technical Support
Support Forum
Customer Care System
Order Now ORDER NOW!
Add to Cart
View Cart
 

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004