Results 1 to 4 of 4

Thread: Additional Error Labels in Ext.FromPanel

  1. #1
    Sencha User
    Join Date
    Feb 2012

    Default Additional Error Labels in Ext.FromPanel

    Hi Guys,

    im currently trying to connect extjs4 with cakephp and i want to display the server validation errors of cakephp as label behind the the fields that didnt validate.

    i already have the field's names and the validation errors, and ext detects whether it was successful or not (Form.submit -> success => true....)

    All i have to do now, is showing them in some kind of labels behind the apporopriate fields.

    My Question: Is the a way to add divs behind each input field ? Or is the a workaround or best practice concerning this topic ? Im pretty new with Ext and i'm currently fighting

    Thanks in Advance

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Munich (Germany)


    take a look at:!...-cfg-msgTarget

    the value "side" seems to fit best. then you will get red error icons at the right side of your field displaying a tooltip with the current error message. this works fine to display server side errors.

    in case none of the options fulfill your needs, you will have to create a custom one.
    Best regards
    Tobias Uhlig

  3. #3
    Sencha User
    Join Date
    Feb 2012


    Could anyone tell me how to access the msgTargets to fill it manually ?
    i have to write my own validation message in there.

    i try to find it through the DOM, but i can't get it yet

    i already have the fields

     var error = String(obj.errors.reason[x]).split(',');
     var field ='input[name="data[User]['+error[0]+']"]');
    error[1] is my validation error message, that i want to put into the msgTarget

    sorry, i'm pretty new to extjs


  4. #4
    Sencha User
    Join Date
    Feb 2012


    I found a solution..

    as the error have a class like 'blabla-errorEl' i could easily find them by Ext.get and do a field.update to write in the appropriate error message from the model validation.

    the model name (here ist is User) is still hardcoded, but you could write a function to the controller, that tells the view, which model is used.

    the Controller Code is
    if ($this->User->save($this->data)) {
                    return json_encode(array('success' => 'true'));
                } else {
                    $errors = $this->User->invalidFields();
                    $response_errors = array();  
                    foreach ($errors as $field => $e) {
                        $response_errors[] = array($field, $e[0]);
                    $response = '{success: false, errors: { reason: '.  json_encode($response_errors).' }}';
                    return $response;
    the Ext4 View:

    buttons: [{ 
                        text:'Add User',
                        handler: function() { 
                            addpanel.getForm().submit( {
                                url: '/test/users/add',
                                success: function(form,action) {
                                failure: function(form,action) { 
                                    var obj = Ext.decode(action.response.responseText); 
                                    for (x in obj.errors.reason) {
                                        var error = String(obj.errors.reason[x]).split(',');
                                        var field = Ext.get('data[User]['+error[0]+']-errorEl');

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts