I'm trying to adjust a slider property editor to my taste.
I wanted to add a rte. The rte renders and it uses the styles. The only thing it doesn't do is store it's value. I don't know where to look and all my googling brought me nowhere...
Bare with me I'm a beginner in angular and I wanted to start with the property editors by modifying and learning on the way.
Ok, I added the piece of code Ian suggested. I never got the console log message. I pasted it below the $scope.rte part.
I see the RTE, I can type and style text. When I click save and publish I see nothing wrong but when I reload the page afterward the text in the RTE is gone....
I would try to maybe change the console log message to a static string just to see if the submitting function is being called at all i would also put a breakpoint on it in chrome. If that is not running at all it would suggest to me some other js error is being thrown which might account for the other problems you're having.
At the moment i can confirm that the reason you are getting empty values is because the rte value element of you angular slide model is never getting populated.
As a test I created an array of rtes (like the $scope.properties example in the link provided) with the 'value' property populated with the 'rte' property value from each slide item in your model.value array. The problem with this approach is that you then need to keep this in sync with your model value array adding and removing from the rtes array each time to add or remove a slide. This is easy enough but then you have the sortable element for your slides which, for everything to work would also need to re sort the list of rtes. Added to this when you re-sort the editors seem to become disabled somehow, and as i haven't used the rte in this way I wouldn't know the fix.
So really there are a few issues before getting something that works
If we could store the rte's in a array with a key value pair it would make life a lot easier right?
If we were to store a hidden Id with a slide and use that Id as a key for a rte, we would be able to connect the 2. We than have to catch the sort event and sort the rte array also.
A quick fix would be to get rid of the sort option to make life a lot easier right?
I'm new to angular and this a whole new game compared to Jquery and razor...
I would look at the archetype package and see how they do things as one of its features is repeatable fields a bit like you are doing in your custom editor. I'm not saying this is code you can just drop straight in but this is some of their code in archetype.js just for you to get some ideas.
$scope.sortableOptions = {
axis: 'y',
cursor: "move",
handle: ".handle",
start: function(ev, ui) {
draggedRteSettings = {};
ui.item.parent().find('.mceNoEditor').each(function () {
// remove all RTEs in the dragged row and save their settings
var id = $(this).attr('id');
draggedRteSettings[id] = _.findWhere(tinyMCE.editors, { id: id }).settings;
tinyMCE.execCommand('mceRemoveEditor', false, id);
});
},
update: function (ev, ui) {
$scope.setDirty();
},
stop: function (ev, ui) {
ui.item.parent().find('.mceNoEditor').each(function () {
var id = $(this).attr('id');
draggedRteSettings[id] = draggedRteSettings[id] || _.findWhere(tinyMCE.editors, { id: id }).settings;
tinyMCE.execCommand('mceRemoveEditor', false, id);
tinyMCE.init(draggedRteSettings[id]);
});
}
};
I haven't tested the ui-sorting, I'm sure there will be some extra tweaking for that.
The RTE configuration is being defined on the global scope for your controller, but the umb-editor is being used inside of ng-repeat, which has it's own scope. The RTE still renders because angular knows to check for properties on the scope recursively through parent scopes, but can't bind the rte's value to each item in your model.value.
The simplest way to resolve this is to add the rte to each item you add to model.value. Try making your $scope.defaultItem as follows:
In your editor, you will want to change the model of umb-editor to slide.rte
<umb-editor model="slide.rte"></umb-editor>
With the above, your rte configuration and it's value is part of each slide item, and the value will be populated with "Enter your slide content here" whenever you add a new slide.
When the rte's content is edited, the value is stored right back to it, so now it should save.
After that you create I create a documenttype called -slider (I use minus as a prefix for my nestedcontent doctypes) with in my case the following properties:
slideTitle - textstring
slideImage - Media Picker
slideText - RTE
After this step I create a Data type using the nested content propertyeditor. In this case called Homepage Slider.
As the documenttype I select -Slider, the tab is de name of the tab you want to use in -Slider. In Name Template i put {{slideTitle}}.
The only thing left is adding a partial view to your template looking something like this:
Could we maybe soon have some documentation for custom sections its getting abit annoying having to hack everything together rather than using the frameworks..
Rte in custom property editor not storing value
I'm trying to adjust a slider property editor to my taste.
I wanted to add a rte. The rte renders and it uses the styles. The only thing it doesn't do is store it's value. I don't know where to look and all my googling brought me nowhere...
Bare with me I'm a beginner in angular and I wanted to start with the property editors by modifying and learning on the way.
Here is the code:
view:
controller:
Can someone point me in the right direction?
Thanks!
What I don't get is that there is no connection to the ng-model used by for example the name property.
I think it has something to do with the rte not being connected to the right model?
Hi Frans I should say that I haven't used the rte in my property editors but you could maybe try to debug the issue by adding this to your controller.
This should reveal what data is being submitted by angular so you can then see if there is anything amiss between that and what you're expecting
Hi Ian,
Thanks for your reply. I'll give it a try hopefully later this day.
Ok, I added the piece of code Ian suggested. I never got the console log message. I pasted it below the $scope.rte part.
I see the RTE, I can type and style text. When I click save and publish I see nothing wrong but when I reload the page afterward the text in the RTE is gone....
I would try to maybe change the console log message to a static string just to see if the submitting function is being called at all i would also put a breakpoint on it in chrome. If that is not running at all it would suggest to me some other js error is being thrown which might account for the other problems you're having.
Oh wow...
Just now I see a error in the console... I didn't see it before becouse it looked like a font error I normaly get with a woff2 file in chrome.
I get this error in the file tinymce.min.js?umb__rnd=7.3.4.1799828241:11:
Could that be the problem?
The double css folder and file refernce is weird...
an error is being generated, however having tested the code the problem lies with the way the rte editor binds to a model. If you look here some of this is explained http://www.enkelmedia.se/blogg/2013/12/4/umbraco-7-use-the-rich-text-editor-tinymce-in-a-custom-section.aspx.
At the moment i can confirm that the reason you are getting empty values is because the rte value element of you angular slide model is never getting populated.
As a test I created an array of rtes (like the $scope.properties example in the link provided) with the 'value' property populated with the 'rte' property value from each slide item in your model.value array. The problem with this approach is that you then need to keep this in sync with your model value array adding and removing from the rtes array each time to add or remove a slide. This is easy enough but then you have the sortable element for your slides which, for everything to work would also need to re sort the list of rtes. Added to this when you re-sort the editors seem to become disabled somehow, and as i haven't used the rte in this way I wouldn't know the fix.
So really there are a few issues before getting something that works
Thanks a lot Ian,
If we could store the rte's in a array with a key value pair it would make life a lot easier right?
If we were to store a hidden Id with a slide and use that Id as a key for a rte, we would be able to connect the 2. We than have to catch the sort event and sort the rte array also.
A quick fix would be to get rid of the sort option to make life a lot easier right?
I'm new to angular and this a whole new game compared to Jquery and razor...
Thanks again!!
I would look at the archetype package and see how they do things as one of its features is repeatable fields a bit like you are doing in your custom editor. I'm not saying this is code you can just drop straight in but this is some of their code in archetype.js just for you to get some ideas.
Thanks for the effort Ian!
I hope I can look into it tomorow. This has become a after hours issue for me as I can't stand it I can't figure this out...
I haven't tested the ui-sorting, I'm sure there will be some extra tweaking for that.
The RTE configuration is being defined on the global scope for your controller, but the
umb-editor
is being used inside of ng-repeat, which has it's own scope. The RTE still renders because angular knows to check for properties on the scope recursively through parent scopes, but can't bind the rte's value to each item in yourmodel.value
.The simplest way to resolve this is to add the rte to each item you add to
model.value
. Try making your$scope.defaultItem
as follows:In your editor, you will want to change the model of
umb-editor
toslide.rte
With the above, your rte configuration and it's value is part of each slide item, and the value will be populated with "Enter your slide content here" whenever you add a new slide.
When the rte's content is edited, the value is stored right back to it, so now it should save.
Hi Rami,
Sorry for the late reply! Thanks for looking in to it.
Meanwhile I've diverted NestedContent for sliders. Absolutely no problem with all the propertyeditors.
Frans
Well that sounds useful! Please share and make some of our lives easier :)
First install NestedContent (package or nuget)
After that you create I create a documenttype called -slider (I use minus as a prefix for my nestedcontent doctypes) with in my case the following properties:
slideTitle - textstring slideImage - Media Picker slideText - RTE
After this step I create a Data type using the nested content propertyeditor. In this case called Homepage Slider.
As the documenttype I select -Slider, the tab is de name of the tab you want to use in -Slider. In Name Template i put {{slideTitle}}.
The only thing left is adding a partial view to your template looking something like this:
The end result looks something like this:
Hi,
I get $scope.setDirty is not a function - have I missed something?
Could we maybe soon have some documentation for custom sections its getting abit annoying having to hack everything together rather than using the frameworks..
is working on a reply...