user1999
user1999

Reputation: 87

JS-GRID: How to set default value

I'm using JS-GRID. How can i set default value to input?

I tried following code. But not successful

Demo Link Here

fields: [
{ name: "addresse", type: "text", width: 500, validate: "required",
            insertValue: function(){
                return "My Default value";
            }
        },
]

enter image description here

Upvotes: 1

Views: 4475

Answers (2)

tabalin
tabalin

Reputation: 2313

Yes, this works, but probably even better would be to override insertTemplate instead custom implementation (in this case you don't need to take care of insertValue).

insertTemplate: function() {
    var $result = jsGrid.fields.text.prototype.insertTemplate.call(this); // original input

    $result.val('My Default Value');

    return $result;
}

As described in this issue on GitHub https://github.com/tabalinas/jsgrid/issues/471

Upvotes: 3

user1999
user1999

Reputation: 87

Okay. My problem has solved.

insertTemplate: function() { 
      return $("<input>").attr("type", "text").attr("value", "My Default value");
}

Upvotes: 1

Related Questions