I have written my own custom property editor in Umbraco 7.1.6 which is essentially a text area field with a character limit. The aim is to allow a developer to specify a limit on a field in the back end so that content editors are notified as to how many characters they have remaining and if they go over that limit the content is trimmed.
I have successfully added the field to my data types but for some reason the Javascript does not appear to fire and the property editor just behaves like a normal textarea with no update to signify that the user has entered any text and notification to symbolise that they have entered over 200 characters.
Does anyone know what I might be doing wrong? Most of the code is from my Umbraco level 2 certification course so it could be that the code is fundamentally wrong but here goes:
All of the above files have been added into their own folder called 'CharacterLimit' which is stored in the 'App_Plugins' folder in my Visual Studio project. Any help would be greatly appreciated.
N.B. I've checked for Javascript errros in the page and this suggests that $scope is not defined. This would explain why the Javascript is not firing but why is $scope undefined?
Thanks for this. I'll give it a try later.
Unfortunately this means all of the documentation I was given on this during the Umbraco Level 2 certification course appears to be incorrect if your solution is the correct method of doing things.
Well I've included the code from Maff's example and now my field isn't appearing at all. Can you confirm whether or not is should be 'notificationService' or 'notificationServices' as there appears to be a mishmash of both in the code above.
I'm also getting the following error now in Firebug:
That's the one I copied word for word after finding my documentation from the level 2 course was incorrect however I would really like it to work with the notification service for a more integrated feel.
Okay, I've given that a go using 'notificationsService' and my control now displays. For some reason however it no longer restricts the amount of characters and allows the user to type more than 200 characters (although the countdown works) and also the notifications service is not working I was expecting it to flag up an error either when the character limit hit 200 or when I attempted to save more than this. After inspecting in Firebug, I'm now getting the following error:
Error: notificationsService is not defined
$scope.limitChars@http://localhost:49439/App_Plugins/CharLimit/charlimit.controller.js:11:8
Rc/s/<@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:74:81
Xc/this.$get</e.prototype.$eval@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:92:261
zd<.link/<@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:152:449
xd</this.$setViewValue/<@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:151:480
n@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:6:468
xd</this.$setViewValue@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:151:436
Va/i/<@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:120:174
Xc/this.$get</e.prototype.$eval@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:92:261
Xc/this.$get</e.prototype.$apply@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:92:374
Va/i@http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js:120:136
x.event.dispatch@http://localhost:49439/umbraco/lib/jquery/jquery-2.0.3.min.js:10:11716
x.event.add/y.handle@http://localhost:49439/umbraco/lib/jquery/jquery-2.0.3.min.js:10:7816
http://localhost:49439/umbraco/lib/angular/1.1.5/angular.min.js
Line 63
$scope is not defined - Custom Property Editor
Hi all,
I have written my own custom property editor in Umbraco 7.1.6 which is essentially a text area field with a character limit. The aim is to allow a developer to specify a limit on a field in the back end so that content editors are notified as to how many characters they have remaining and if they go over that limit the content is trimmed.
I have successfully added the field to my data types but for some reason the Javascript does not appear to fire and the property editor just behaves like a normal textarea with no update to signify that the user has entered any text and notification to symbolise that they have entered over 200 characters.
Does anyone know what I might be doing wrong? Most of the code is from my Umbraco level 2 certification course so it could be that the code is fundamentally wrong but here goes:
Package.Manifest
characterlimit.controller.js
characterlimit.html
All of the above files have been added into their own folder called 'CharacterLimit' which is stored in the 'App_Plugins' folder in my Visual Studio project. Any help would be greatly appreciated.
N.B. I've checked for Javascript errros in the page and this suggests that $scope is not defined. This would explain why the Javascript is not firing but why is $scope undefined?
Hi Jason,
You're not injecting the scope into your controller correctly - try this:
Check out this tutorial for more info:
http://viralpatel.net/blogs/angularjs-controller-tutorial/
Cheers,
Maff
Hi Maff,
Thanks for this. I'll give it a try later. Unfortunately this means all of the documentation I was given on this during the Umbraco Level 2 certification course appears to be incorrect if your solution is the correct method of doing things.
Cheers,
Jason
No worries - let me know how you get on.
Cheers,
Maff
Can you check in if the javascript file is loaded.You can do this in chrome developer tools on the network tab.
Make sure you set debug to true in your web.config. So the client dependency framework doens't minify and combine your scripts
Dave
Well I've included the code from Maff's example and now my field isn't appearing at all. Can you confirm whether or not is should be 'notificationService' or 'notificationServices' as there appears to be a mishmash of both in the code above.
I'm also getting the following error now in Firebug:
You need to use notificationsService with the double s.
Also your first code for the controller should be correct.
Also Tim from HQ has a blog about a char limit editor : http://www.nibble.be/?p=285
Maybe that can be a starting point
That's the one I copied word for word after finding my documentation from the level 2 course was incorrect however I would really like it to work with the notification service for a more integrated feel.
Okay, I've given that a go using 'notificationsService' and my control now displays. For some reason however it no longer restricts the amount of characters and allows the user to type more than 200 characters (although the countdown works) and also the notifications service is not working I was expecting it to flag up an error either when the character limit hit 200 or when I attempted to save more than this. After inspecting in Firebug, I'm now getting the following error:
Can you post the code you have now ? So I can try to pinpoint the problem.
Dave
Certainly:
Found the problem. It is in your controller. This works for me :
I'm afraid this is what I've tried before and unfortunately it doesn't work.
I tried too, still doesn't work for me too. Did you try anything else?
Strange...that exact code works at my end.
Some tips for debugging this.
Set the debug attribute to true on the compilation tag in your web.config. This will stop the client dependency from minifying and combining scripts.
Open the chrome developer tools and disable cache on the network tab. This way you are sure the latest version of your scripts is loaded.
If you get errors in the console please share them.
Dave
is working on a reply...