javascript - Disabling enter with angular in a content-editable -


i want nothing happen if press enter while in content-editable:

this tried inside directive:

element.on('blur keyup change', function (e) {                         if(e.which == '13')                             e.preventdefault(); 

here entire directive:

    .directive('contenteditable', function () {       return {           restrict: 'a', // activate on element attribute           require: '?ngmodel', // hold of ngmodelcontroller           link: function (scope, element, attrs, ngmodel) {               if (!ngmodel) return; // nothing if no ng-model                // specify how ui should updated               ngmodel.$render = function () {                   element.html(ngmodel.$viewvalue || '');               };                // listen change events enable binding               element.on('blur keyup change', function (e) {                     if(e.which == '13')                         e.preventdefault();                     scope.$apply(readviewtext);               });                // no need initialize, angularjs initialize text based on ng-model attribute                // write data model               function readviewtext() {                     var html = element.html();                     //cleaning out html saving data.                     console.log(html);                     html = html.replace(/(<([^>]+)>)/ig,"");                     /*  .replace(/<div><br\s*[\/]?><\/div>/gi,'')                         .replace(/<div>/gi,'\n')                         .replace(/<\/div>/gi,'')                         .replace(/<br\s*[\/]?>/gi,'');*/                     console.log(html)                     ngmodel.$setviewvalue(html);               }           }       };   }); 

i ended doing this:

      element.on('keydown', function (event){             if(event.which == '13'){                 window.event.cancelbubble = true;                 event.returnvalue = false;                 inserttextatcursor('\n');             }       }); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -