I am trying to create a new Trait for a component. The textarea appears but it is not saving when trying to edit back, and the object has no "content" attribute. Why? I am basically using the code from here: https://github.com/artf/grapesjs/wiki/Traits#define-new-trait-type
// Each new type extends the default Trait
editor.TraitManager.addType('content', {
events:{
'keyup': 'onChange', // trigger parent onChange method on keyup
},
/**
* Returns the input element
* @return {HTMLElement}
*/
getInputEl: function() {
var selectedModel = this.target;
var input = document.createElement('textarea');
input.value = selectedModel.get('content');
return input;
},
/**
* Triggered when the value of the model is changed
*/
onValueChange: function () {
this.target.set('content', this.model.get('value'));
}
});
Thank you!
Hi @NETCreator-US can you try with this and let me know if it works:
/**
* Returns the input element
* @return {HTMLElement}
*/
getInputEl: function() {
if(!this.inputEl) {
var input = document.createElement('textarea');
input.value = this.target.get('content');
this.inputEl = input;
}
return this.inputEl;
},
Thank you, @artf ! It works now.
Cool, this worked for me.
Could you please update the example on https://github.com/artf/grapesjs/wiki/Traits#define-new-trait-type with this code. I took some serieus time before i found this bug report.
done
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.