jquery populate form json
//Plugin
(function($){
$.fn.setFormData = function(data){
let t = this;
$.each(data, function(key, value) {
var ctrl = $(t).find('[name='+key+']');
switch(ctrl.prop("type")) {
case "radio": case "checkbox": case "select":
ctrl.each(function() {
if($(this).attr('value') == value) $(this).attr("checked",value);
});
break;
case "select" :
// manipulate select?
ctrl.val(value);
break;
default:
ctrl.val(value);
}
});
}
})(jQuery);
//Call
$('#form').setFormData(someData);
Also in JavaScript:
- javascript check if objects are equal
- date angular
- javascript get array difference
- funciones invocan a funciones javascript
- $q use in angularjs
- updating a key value on javascript object es6
- jspdf reduce size file
- IFFI in js
- bind jquery
- implement cai webchat in react native
- how do you create a function js?
- show hand icon on hover javascript
- javascript remove element from array
- format a date moment
- nodejs shebang
- what is react native
- json opposite of stringify
- convertir seconde
- javascript addeventlistener
- hiding header in a specific screen in react native
- random int between two numbers javascript
- .fetch method
- jquery get value of element
- js page reload