0

I have the following code snippet which is invoked when edit button in grid is clicked a window pops up

edit: function(e) {
$('input[name="prods"]').each(function()
{
    var textarea = $(document.createElement('textarea'));
    textarea.text($(this).val());

    $(this).after(textarea).remove();
}); 
}

A text box input type is converted to textarea which works fine.

Once it is converted to textarea, how do I assign the value of textarea to $('input[name="prods"]') when save button is clicked of popup window?

Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50
Jacob
  • 14,463
  • 65
  • 207
  • 320

3 Answers3

1

Please try with the below code snippet. We have to retrieve value from the textArea and assigned its value into model property.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Untitled</title>

    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.2.624/styles/kendo.common.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.2.624/styles/kendo.rtl.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.2.624/styles/kendo.default.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.2.624/styles/kendo.dataviz.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.2.624/styles/kendo.dataviz.default.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.2.624/styles/kendo.mobile.all.min.css">

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://cdn.kendostatic.com/2015.2.624/js/angular.min.js"></script>
    <script src="http://cdn.kendostatic.com/2015.2.624/js/jszip.min.js"></script>
    <script src="http://cdn.kendostatic.com/2015.2.624/js/kendo.all.min.js"></script>
</head>
<body>
    <div id="example" class="k-content">
        <div id="grid"></div>
    </div>



    <script>
        $(document).ready(function () {
            var crudServiceBaseUrl = "http://demos.telerik.com/kendo-ui/service",
                dataSource = new kendo.data.DataSource({
                    transport: {
                        read: {
                            url: crudServiceBaseUrl + "/Products",
                            dataType: "jsonp"
                        },
                        update: {
                            url: crudServiceBaseUrl + "/Products/Update",
                            dataType: "jsonp"
                        },
                        destroy: {
                            url: crudServiceBaseUrl + "/Products/Destroy",
                            dataType: "jsonp"
                        },
                        create: {
                            url: crudServiceBaseUrl + "/Products/Create",
                            dataType: "jsonp"
                        },
                        parameterMap: function (options, operation) {
                            if (operation !== "read" && options.models) {
                                return { models: kendo.stringify(options.models) };
                            }
                        }
                    },
                    batch: true,
                    pageSize: 20,
                    schema: {
                        model: {
                            id: "ProductID",
                            fields: {
                                ProductID: { editable: false, nullable: true },
                                ProductName: { validation: { required: true } },
                                UnitPrice: { type: "number", validation: { required: true, min: 1 } },
                                Discontinued: { type: "boolean" },
                                UnitsInStock: { type: "number", validation: { min: 0, required: true } }
                            }
                        }
                    }
                });

            $("#grid").kendoGrid({
                dataSource: dataSource,
                pageable: true,
                height: 550,
                toolbar: ["create"],
                columns: [
                    { field: "ProductName", title: "Product Name" },
                    { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "120px" },
                    { field: "UnitsInStock", title: "Units In Stock", width: "120px" },
                    { field: "Discontinued", width: "120px" },
                    { command: ["edit", "destroy"], title: "&nbsp;", width: "250px" }],
                editable: "popup",
                edit: function (e) {
                    $('input[name="ProductName"]').each(function () {
                        var textarea = $(document.createElement('textarea'));
                        textarea.attr("id", "txtProductName");
                        textarea.text($(this).val());

                        $(this).after(textarea).remove();
                    });
                },
                save: function (e) {
                    e.model.ProductName = $('#txtProductName').val();
                }
            });
        });
    </script>
</body>
</html>

Let me know if any concern.

Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50
0

Could this be a mix of val and text? textarea.text seems wrong, that would normally be textarea.val('whatever')

Here this is covered:

jQuery get textarea text

Community
  • 1
  • 1
Thomas Koelle
  • 3,416
  • 2
  • 23
  • 44
0

You can use this method as well ..

<div class="ref">
<input type="text" name="prod" value="TEST"/>
</div>


jQuery('.edit').click(function(){

var val = jQuery('input[name="prod"]').val()
jQuery('.ref').html('<textarea name="prod">'+val+'</textarea>');

});