1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    5
    Vote Rating
    0
    duderion is on a distinguished road

      0  

    Default Additional Error Labels in Ext.FromPanel

    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
    Duderion

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,669
    Vote Rating
    110
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    take a look at:
    http://docs.sencha.com/ext-js/4-0/#!...-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
    __________

    S-CIRCLES Social Network Engine

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    5
    Vote Rating
    0
    duderion is on a distinguished road

      0  

    Default


    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

    Code:
     var error = String(obj.errors.reason[x]).split(',');
     var field = Ext.select('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

    duderion

  4. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    5
    Vote Rating
    0
    duderion is on a distinguished road

      0  

    Default


    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
    Code:
    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:

    Code:
    buttons: [{ 
                        text:'Add User',
                        handler: function() { 
                            addpanel.getForm().submit( {
                                url: '/test/users/add',
                                success: function(form,action) {
                                    alert('true');
                                },
                                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');
                                        field.update(error[1]).show();                               
                                    }
                                }  
                            })
                        }
                    }]
    cya
    dude

Thread Participants: 1

Tags for this Thread