Hollstar
Junior Member
Posts: 9
Registered: 4/4/2008
Location: Australia
Member Is Offline
|
| posted on 4/4/2008 at 10:43 PM |
|
|
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! :(
|
|
|
tigra
Administrator
Posts: 1960
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 4/5/2008 at 04:49 AM |
|
|
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).
|
|
|
Hollstar
Junior Member
Posts: 9
Registered: 4/4/2008
Location: Australia
Member Is Offline
|
| posted on 4/5/2008 at 08:41 AM |
|
|
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?
|
|
|
tigra
Administrator
Posts: 1960
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 4/5/2008 at 02:29 PM |
|
|
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.
|
|
|
Hollstar
Junior Member
Posts: 9
Registered: 4/4/2008
Location: Australia
Member Is Offline
|
| posted on 4/6/2008 at 09:41 AM |
|
|
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?
|
|
|
Hollstar
Junior Member
Posts: 9
Registered: 4/4/2008
Location: Australia
Member Is Offline
|
| posted on 4/8/2008 at 09:15 AM |
|
|
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! :)
|
|
|
tigra
Administrator
Posts: 1960
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 4/9/2008 at 12:39 AM |
|
|
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.
|
|
|