Page 1 of 1

Make all columns in a grid required...?

PostPosted: Thu Mar 17, 2011 11:10 am
by wermy
Hi,
First of all, this program is exactly what I was looking for - thanks!

I'm using the method described here to create multiple records across several tables via one form: viewtopic.php?t=4884#23898

The problem I'm having is that one of the grids has multiple required fields... But as long as one of the fields is filled in, it doesn't complain when creating the record. Is there a way to fix this?

For clarity, this is how it's set up:
I have a "docs" table, and tables for authors, subjects, and links. I have defined relationships to each with the docs table being the source. When a user creates a new docs record, they have fields for creating a (possibly more than one) author, subject, and link. Each of those are required. The links grid has two columns, one for a url and one for a type. I need both to be required, but when I set the validators:required=1 on the grid (as well as the fields.ini file for the link table, but I don't think it's looking at that), it only looks for one column to be filled out. Any advice? Thanks!

Re: Make all columns in a grid required...?

PostPosted: Thu Mar 17, 2011 11:49 am
by shannah
This is likely a bug.
If you try adding a new record directly in the links table, do the fields show up correctly as required?
-Steve

Re: Make all columns in a grid required...?

PostPosted: Fri Mar 18, 2011 8:06 am
by wermy
Hi,
Thanks for the reply! Yes if I ad directly to the fields table, both fields show as required. They were defined as not null when I created the table, but I also added the validators:required=1 to the links fields.ini - still did not fix it.

Re: Make all columns in a grid required...?

PostPosted: Mon Mar 21, 2011 10:03 am
by wermy
Hi again,
Is there a way I can do some validation with a trigger to make sure both fields on that grid are filled out? If so, would I use beforeAddRelatedRecord? I've been looking through the documentation, and I'm afraid I'm a bit lost. Thanks again.

Re: Make all columns in a grid required...?

PostPosted: Tue Mar 22, 2011 12:19 pm
by wermy
Hi once again, :)

I had another idea - could I check that all the fields are filled using javascript? I gather that would be something I do with customization of templates - but at what point? On the submit button, or after they change from the first field in the grid (there are two fields int he grid in question)? Thanks again

Re: Make all columns in a grid required...?

PostPosted: Tue Mar 22, 2011 2:30 pm
by shannah
After looking at the code I think the best place to add this validation is by adding a handler for the submit event of the actual form (i.e. <form> tag).

If you're comfortable with jQuery it should be easy to check for the information you want. In your handler you'd basically display an alert if any rows didn't meet your requirements. Returning false from a submit handler causes the form submission to be cancelled.

The reason for this is that the hook to add a new row is fired as soon as the user enters anything in any of the fields of the last row of the grid. This is before any "required" validation could reasonably take place. The ideal solution would be to listen for "blur" events on fields in the grid - but these would have to be checked against the next field that is focused, because if the focus is still in the same row, we don't need to perform the validation.

Hence as a one-off solution it is just easiest to check all of the rows at the time of form submission.

-Steve