Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: RowEditor startEdit and validation

  1. #1
    Member
    Join Date
    Nov 2011
    Posts
    6

    RowEditor startEdit and validation

    I am using a RowEditor in a fairly standard scenario with most of the code taken from the demos. I have an add button that I've wired up in what seems to be a fairly standard way:

    Code:
    var grid = #{GridPanel1};
    grid.getRowEditor().stopEditing();
    
    grid.insertRecord(0, {
    name   : ""
    });
    
    grid.getView().refresh();
    grid.getSelectionModel().selectRow(0);
    grid.getRowEditor().startEditing(0);
    I have some validation attached to the 'name' textfield. The validation prevents a range of inputs including the empty string. That all works fine. If the user edits a row, they have to cancel or fix any validation errors before they can commit the row or select another row. No problems here.

    The validation is a custom validation function configured like so:

    Code:
    <ext:TextField ... Validator="myValidationFunction" ... />
    However, I've run into the following scenario:

    When I add a row, I can't really provide a valid default for the 'name' field. I default the field value to an empty string as per the example above.

    The user clicks the add button, they get the new row and RowEditor appearing, and the roweditor even shows the correct validation error (empty strings are not allowed). This is fine.

    The problem is that the user is then able to select another row and is NOT prevented from doing this even though the input is invalid. The result is a new row with invalid data.

    I'm guessing this is because I'm doing an 'add' and then an 'edit' and the grid/roweditor doesn't force the user to supply a valid input if they did not change the original field value (even if the original field value was invalid).

    If I'm not missing anything obvious, is there any reasonable workaround for this? I've tried solving this with the RowEditor Before/After edit events or by looking at ways to change the field value to trick the RowEditor into thinking the value has been changed. No luck so far.

  2. #2
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,290
    Hi,

    Please use ValidateEdit.
    http://forums.ext.net/showthread.php?15034
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  3. #3
    Member
    Join Date
    Nov 2011
    Posts
    6
    The ValidateEdit event does not fire in the scenario I described. This was one of the first things I tried. I also couldn't find any other events that would let me do something similar.

  4. #4
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,290
    Could you provide a sample to test with?
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  5. #5
    Member
    Join Date
    Nov 2011
    Posts
    6
    I can provide a project sample but I think the problem can be demonstrated in the gridpanel/plugins/roweditor demo. In the demo, how would you prevent the user from adding a row with "New Guy" as the name? (meaning, if you needed to keep the default as New Guy, how could you ensure that the user changes it to a real name when they add a new row?)

  6. #6
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,290
    You could try to handle the Change event of a TextField.
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  7. #7
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,290
    Though I'd suggest you to set up custom validation for an Editor.

    Example
    Code:
    <ext:Column 
        Header="First Name" 
        DataIndex="name" >
        <Editor>
            <ext:TextField 
                runat="server" 
                AllowBlank="false" 
                Validator="function (v) { 
                                if (v === 'New Guy') {
                                    return 'Enter name';
                                } 
                            }" />
        </Editor>
    </ext:Column>
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  8. #8
    Member
    Join Date
    Nov 2011
    Posts
    6
    I tried the editor control validation approach but unfortunately this don't address the problem.

    The problem, as I see it, is that the row editor doesn't lock the user to the row if the user hasn't made any changes to the data in the row, even if that data doesn't pass validation. I think this behaviour is fine, but it doesn't work very well with the add-to-store-and-start-edit approach for adding a new row.

    I have worked around the problem but in a less than ideal way. It would be nice to find a solution to what, in my mind, is a fairly standard scenario.

  9. #9
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,290
    Quote Originally Posted by ralex View Post
    I tried the editor control validation approach but unfortunately this don't address the problem.
    Please clarify why.
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  10. #10
    Member
    Join Date
    Nov 2011
    Posts
    6
    A user can still move to another row after doing an add. The validation does not stop that. You can easily test this by adding the bit of validation to the RowEditor demo and see that this is the case.

Similar Threads

  1. Remote Validation using RowEditor
    By mait_k in forum 1.x Help
    Replies: 1
    Last Post: Dec 20, 2011, 4:24 PM
  2. RowEditor validation
    By reezvi in forum 1.x Help
    Replies: 0
    Last Post: Aug 12, 2011, 6:36 PM
  3. [CLOSED] RowEditor & Form Validation
    By ljcorreia in forum 1.x Premium Help
    Replies: 4
    Last Post: Jul 22, 2011, 9:45 AM
  4. [CLOSED] RowEditor Validation
    By ljcorreia in forum 1.x Premium Help
    Replies: 1
    Last Post: Jul 20, 2011, 12:21 PM
  5. Replies: 2
    Last Post: Feb 09, 2010, 8:04 AM

Tags for this Thread

Posting Permissions