Single form representing multiple of the same class

8 views
Skip to first unread message

Jason Durham

unread,
Jan 27, 2014, 1:30:03 PM1/27/14
to valida...@googlegroups.com
I'm working on a checkout path for an e-commerce site.  One particular form has a billing address and shipping address displayed on it. Each of these are represented in our object model as an instance of the same class (Address.cfc).  The client field names must be unique, and I can't figure out how to make the client-side validation work where a single property may have multiple client field names.  

Is this scenario supported with VT?  If so, how have you solved this scenario?

Jason Durham

John Whish

unread,
Jan 27, 2014, 4:34:32 PM1/27/14
to valida...@googlegroups.com
Hi Jason,

You can reuse the same object with different validation rules. I've a similar application where the Address object was used for both Billing and Shipping addresses by using contexts. In my case I had the forms on separate views which made it a bit easier, but I think you may be able to use the clientfieldname attribute in the XML rules file to define an id for the field.

HTH

John


--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to validatethis...@googlegroups.com.
To post to this group, send email to valida...@googlegroups.com.
Visit this group at http://groups.google.com/group/validatethis.
For more options, visit https://groups.google.com/groups/opt_out.

Jason Durham

unread,
Jan 28, 2014, 1:35:34 PM1/28/14
to valida...@googlegroups.com
Thanks for the reply, John.  I'm not sure I understand correctly. By default VT, will use the name of the <property> to create the client-side validation. 

<property name="city">
<rule type="required" />
</property>

If I use "clientfieldname", the default behavior of VT is overridden to only look for a match using this setting.

<property name="city" clientfieldname="shipCity">
<rule type="required" />
</property>

That directive will no longer match my <input name="city" /> field.  Therefore, I'll need a unique <property> for each duplicate field.

<property name="city">
<rule type="required" />
</property>

<property name="city" clientfieldname="shipCity">
<rule type="required" />
</property>

I believe your other suggestion was to use a unique context for the shipping versions of the fields.

<property name="city">
<rule type="required" />
</property>

<property name="city" clientfieldname="shipCity">
<rule type="required" contexts="myContext" />
</property>

I'm not sure if VT will allow multiple <property> nodes with the same name attribute.  If it doesn't I could simply name the 2nd <property> to what I would have put in the clientfieldname (shipCity in this example).

<property name="city">
<rule type="required" />
</property>

<property name="shipCity" desc="city">
<rule type="required" contexts="myContext" />
</property>

Am I correct in any assumptions I made? 

Thanks,
Jason


Jason Durham
Reply all
Reply to author
Forward
0 new messages