1

I'm using symfony framework to develop a website. My form looks like this

<li class="fields">
    <label>Date de début* :</label>
    div class="field">
        <select id="agenda_date_debut_day" name="agenda[date_debut][day]" class="required w_auto required">
            <option selected="selected" value=""></option>
            <option value="1">1</option>
            ...
        </select>
        <select id="agenda_date_debut_month" name="agenda[date_debut][month]" class="required w_auto required">
            <option selected="selected" value=""></option>
            <option value="1">1</option>
            ...
        </select>
        <select id="agenda_date_debut_year" name="agenda[date_debut][year]" class="required w_auto required">
            <option selected="selected" value=""></option>
            <option value="1">1</option>
            ...
        </select>
    </div>
</li>   

I tried something like this but it doesn't worked:

var validator = $(".validate_form").validate({
    groups: {
      /*dateDebut: '"agenda[date_debut][day]" "agenda[date_debut][month]" "agenda[date_debut][year]"'*/
      dateDebut: "agenda[date_debut][day] agenda[date_debut][month] agenda[date_debut][year]"
},
errorPlacement: function(label, element) {
    if (/^dateDebut/.test(element[0].name)) {
    label.insertAfter("#agenda_date_debut_year");
    } 
    ...
 }
 ...

}

I read a lot of posts about how to use name attribut but I don't figure out how to deal with mine. As I said, I'm using symfony, so I can't change the attribut name to remove the [].

Maybe, it' s possible to alter the plugin to use id instead of name but I don't figure how to do it.

Someone can help me, please

Thks

mike
  • 17
  • 6
  • I am also struk with same problem please let me know when you find answer –  Feb 09 '11 at 21:57

2 Answers2

0

It actually works fine with brackets in the name.

For instance, I have:

$(document).ready(function(){
  $("#coppa_users_form form").validate({
    rules: {
      "coppa_user[user_attributes][username]": {
        required: true,
        minlength: 3
      }
    },
    messages: {
      "coppa_user[user_attributes][username]": "<p class='errormsg'>Please enter at least three characters</p>"
    }
  });
});

And this works fine. Possibly check if there are any conflicts in the JS above where this is being called?

Vu Nguyen
  • 215
  • 1
  • 10
-1

You need to escape brackets with a backslash for the regexp test to work: "agenda\[date_debut\]\[day\] agenda\[date_debut\]\[month\] agenda\[date_debut\]\[year\]"

scragz
  • 6,670
  • 2
  • 23
  • 23