This is a migrated thread and some comments may be shown as answers.

[Solved] get the id of a textbox in a grid when in edit mode?

1 Answer 570 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 02 Oct 2014, 02:42 PM
How do I get the id of a textbox in a grid when it is in edit mode?

I have a grid and when I am in edit mode I want to pass the email address typed into the textbox to the controller via ajax and see if the already registered.

Here is my code so far, which by the way works if I was just filling in a standard form!

The grid:
@(Html.Kendo().Grid<ExternalTrainingDashboard.ViewModel.TraineeViewModel>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.ForeignKey(p => p.TitleID, (System.Collections.IEnumerable)ViewData["titles"], "TitleID", "Title");
            columns.Bound(p => p.FirstName);
            columns.Bound(p => p.LastName);
            columns.Bound(p => p.EmailAddress);
            columns.Command(command =>
            {
                command.Edit();
            });
        })
        .ToolBar(toolBar =>
               {
                   toolBar.Create().Text("Create New Trainee");
               })
        .Editable(editable => editable.Mode(GridEditMode.InLine))
        .DataSource(dataSource => dataSource
                  .Ajax()
                      .Events(events => events.Error("error_handler"))
                      .Model(
                      model =>
                      {
                          model.Id(p => p.TraineeID);
                      })
                      .Read(read => read.Action("Trainee_Read", "Trainee"))
                      .Update(edit => edit.Action("Trainee_Update", "Trainee"))
                      .Create(create => create.Action("Trainee_Create", "Trainee"))
              )
    )


And my javascript:
<script type="text/javascript">

    $(function () {

        var msg = $("#emailaddress-message");
      
        $("#EmailAddress").blur(function () { 
            
           var emailaddress = $(this).val();

            if (emailaddress.length == 0) {
                alert("No Email Address.");
                return;
            }

            $.ajax({
                url: '@Url.Action("CheckForUniqueEmail", "Trainee")',
                dataType: 'json',
                type: 'GET',
                data: { EmailAddress: emailaddress },
                success: OnCheckForUniqueUserSuccess,
                error: OnCheckForUniqueUserError
            });
        });

        function OnCheckForUniqueUserSuccess(data) {
            if (data.Exists) {
                msg.text("This Email Address is already in use.  Please enter a new one.");
                btn.attr("disabled", "disabled");
            } else {
                msg.text("");
                btn.removeAttr("disabled");
            }
        }

        function OnCheckForUniqueUserError(xhr, status, error) {
            msg.text("There was an error checking uniqueness.");
        }
    });

</script>

But the blur function is not triggering, I am guess this in because I don't have the correct id of the email address text box??


1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 06 Oct 2014, 08:45 AM
Hello Stephen,

You should be aware that the editor is created every time the cell is opened for editing and destroyed every time the cell is closed.
That said, the editor input will be rendered in the DOM when the "edit" event of the Grid is triggered. Please select the input by ID at the edit event handler.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or