Use $each() and console.log() both the key and the element. The solution
will jump out at you right away.

(The solution, of course, is that you need to access the "isEmpty" key in
each of your "key" values, which are themselves objects.)


On Sat, May 1, 2010 at 3:10 PM, Meroe <[email protected]> wrote:

> Hell folks,
>
> I'm new to mootools and have found myself stuck with iterating over a
> JSON response.
>
> My JSON response is:
>
> {"password":{"isEmpty":"Value is required and can't be
> empty"},"passwordconfirm":{"isEmpty":"Value is required and can't be
> empty"},"costrate":{"isEmpty":"Value is required and can't be
> empty"},"firstname":{"isEmpty":"Value is required and can't be
> empty"},"lastname":{"isEmpty":"Value is required and can't be
> empty"},"username":{"isEmpty":"Value is required and can't be
> empty"},"officenumber":{"isEmpty":"Value is required and can't be
> empty"},"email":{"isEmpty":"Value is required and can't be empty"}}
>
> My form submit call (I received help on the loop from IRC last night
> so thanks):
>   $('form').addEvent('submit', function(e){
>                    e.stop();
>                    this.set('send', {
>                        onComplete: function(response){
>                            var errors = JSON.decode(response);
>                            for (var key in errors) {
>                                var o = '<ul id="errors-' + key + '"
> class="errors">';
>                                o += '<li>' + errors[key] + '</li>';
>                                o += '</ul>';
>                            }
>                        }
>                    });
>
>                    this.send();
>                });
>
> My console.log of var o is:
>
> <ul id="errors-email" class="errors"><li>[object Object]</li></ul>
>
> So you can see I have two problems at least.  #1 it is not iterating
> over the entire response (it is just doing email) so that tells me I
> have a loop problem.  And #2 the error message (from the JSON
> response) should be Value is required and can't be empty.
>
> I'm sure i'm missing something basic, but I'm completely stuck and
> looking for some assistance.
>

Reply via email to