I have this working, but not the most user friendly.  The case is
there is a combination of fields that must meet a criteria, uniqueness
in this case.  The problem I am finding is that the rules are all
attached to fields, where this case really applies to the form in
general.

In this example, an end user is adding a Member record.  A member is a
combination of a User and a Group.  Users can join many groups, groups
have many users.  A user cannot join the same group twice, so the
alternate, natural key to the Member database table is usr_id,
group_id.

The form has fields with id of user and group.

While it does work, when an error is detected, the field you just
changed is marked with the error.  The other field in the pair is not
marked as being invalid.  If I go and change the other field to make a
valid combination, the other field still shows as being in the error
state.

Looking for ideas to implement an N field validation nicely.  (I used
a ClassRule for single field unique checks, but that doesn't help
here.)

Thanks,

Ted

------------------------
 var constraint = ['user', 'group'];

        $.each(constraint, function(index, value) {
            $("#" + value).rules("add", {
                remote: {
                    url:  "/myapp/unique/composite",
                    type: "get",
                    data: {
                        classname: function() {
                            return $("#classname").val();
                        },
                        constraints: function() {
                            var result = "";
                            $.each(constraint, function(i, v) {
                                if (i > 0) {
                                    result = result + ";";
                                }
                                result = result + v + ':' + $("#" +
v).val();
                            });
                            return result;
                        },
                        id: function() {
                            return $("#id").val();
                        }
                    }
                },
                messages: {
                    remote: "The combination of " + constraint + "
must be unique."
                }
            });
-----------------------------



Reply via email to