RowEditor startEdit and validation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    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:

    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:

    <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
    Hi,

    Please use ValidateEdit.
    http://forums.ext.net/showthread.php?15034
  3. #3
    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
    Could you provide a sample to test with?
  5. #5
    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
    You could try to handle the Change event of a TextField.
  7. #7
    Though I'd suggest you to set up custom validation for an Editor.

    Example
    <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>

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 Legacy Premium Help
    Replies: 4
    Last Post: Jul 22, 2011, 9:45 AM
  4. [CLOSED] RowEditor Validation
    By ljcorreia in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 20, 2011, 12:21 PM
  5. [CLOSED] [1.0] RowEditor validation tooltip obstructing editing
    By tdracz in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 09, 2010, 8:04 AM

Tags for this Thread

Posting Permissions