Browse Source

Fix select traits

pull/67/head
Artur Arseniev 9 years ago
parent
commit
366be024a8
  1. 7
      index.html
  2. 1
      src/demo.js
  3. 43
      src/trait_manager/view/TraitSelectView.js

7
index.html

@ -17,6 +17,13 @@
<form action="##">
<input name="name" placeholder="Name" class="sub-input">
<input name="email" placeholder="Email" class="sub-input" type="email">
<textarea placeholder="Some text here" class="sub-input"></textarea>
<select class="sub-input">
<option>Your option</option>
<option value="opt1">Option 1</option>
<option value="opt2">Option 2</option>
<option value="opt3">Option 3</option>
</select>
<button class="sub-btn">Submit</button>
</form>
<header class="header-banner">

1
src/demo.js

@ -333,6 +333,7 @@ require(['config/require-config'], function() {
window.editor = editor;
editor.render();
});
});

43
src/trait_manager/view/TraitSelectView.js

@ -16,33 +16,44 @@ define(['backbone','./TraitView'],
* @private
*/
getInputEl: function() {
if(!this.$input){
if(!this.$input){
var md = this.model;
var opts = md.get('options') || [];
this.input = '<select>';
var opts = md.get('options') || [];
this.input = '<select>';
if(opts.length){
_.each(opts, function(el){
var name, value, style;
var attrs = '';
if(typeof el === 'string'){
name = el;
value = el;
}else{
name = el.name ? el.name : el.value;
value = el.value.replace(/"/g,'&quot;');
style = el.style ? el.style.replace(/"/g,'&quot;') : '';
attrs += style ? 'style="' + style + '"' : '';
}
var name, value, style;
var attrs = '';
if(typeof el === 'string'){
name = el;
value = el;
}else{
name = el.name ? el.name : el.value;
value = el.value.replace(/"/g,'&quot;');
style = el.style ? el.style.replace(/"/g,'&quot;') : '';
attrs += style ? 'style="' + style + '"' : '';
}
this.input += '<option value="' + value + '" ' + attrs + '>' + name + '</option>';
}, this);
}
this.input += '</select>';
this.$input = $(this.input);
// TODO check also model attributes in case of changeProp
var target = this.target;
var name = md.get('name');
var val = md.get('value');
if (md.get('changeProp')) {
val = val || target.get(name);
} else {
var attrs = target.get('attributes');
val = attrs[name];
}
if(val)
this.$input.val(val);
}
}
return this.$input.get(0);
},

Loading…
Cancel
Save