form field with brackets breaks validatethis

28 views
Skip to first unread message

Casey Dougall

unread,
Apr 7, 2013, 3:18:35 PM4/7/13
to valida...@googlegroups.com
Hi,

I have a form auto generated form field that posts as prodSku[]

Validate This doesn't seem to like this much.

Uncaught TypeError: Cannot read property 'form' of undefined

/*<![CDATA[*/jQuery(function($){var $form_AddProductForm = $("#AddProductForm");$form_AddProductForm.validate({ignore:'.ignore'});var fm={};fm['prodSku[]'] = $(":input[name='prodSku[]']",$form_AddProductForm);fm['prodSku[]'].rules("add",{required:true,messages:{required:"Product SKU required, please select a product"}});});/*]]>*/</script>

This is in a coldBox application. my xml is as such...

<?xml version="1.0" encoding="UTF-8"?> <validateThis xsi:noNamespaceSchemaLocation="validateThis.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <objectProperties> <property name="prodSku[]"> <rule type="required" failureMessage="Product SKU required, please select a product" /> </property> </objectProperties> </validateThis>

if I change prodSku[] to prodSku the remaining jquery objects load on the page but of course I won't be able to validate this form field.

is there something I can update in validateThis to allow brackets in a formfield or should I look into this autogenerated field. it's an autosugest function that adds X amount of products which turns the field from prodSku into prodSku[] before posting.

this field is used in other froms so I don't want to mess with it unless I need to, but this one area it's being used requires validation so I need to come up with something to get around the problem.

Thank you to the group for your assistance.

regards,
Casey


John Whish

unread,
May 20, 2013, 2:22:26 PM5/20/13
to valida...@googlegroups.com
Just noticed this post. For reference with jQuery selectors you need to escape the square brackets so this should work:

/*<![CDATA[*/jQuery(function($){var $form_AddProductForm = $("#AddProductForm");$form_AddProductForm.validate({ignore:'.ignore'});var fm={};fm['prodSku\\[\\]'] = $(":input[name='prodSku\\[\\]']",$form_AddProductForm);fm['prodSku\\[\\]'].rules("add",{required:true,messages:{required:"Product SKU required, please select a product"}});});/*]]>*/</script>



--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages