Показаны сообщения с ярлыком html. Показать все сообщения
Показаны сообщения с ярлыком html. Показать все сообщения

пятница, 30 мая 2014 г.

Plain text AngularJS filter

Many times on different web projects there is an requirement to remove HTML tags from the text (that comes from some remote place and should be displayed on the web page). Here I will provide approach, how to do it through AngularJS filter. So, filter code itself:

/**
 * Filter removes HTML from given string value.
 */
angular.module("myApp").filter('plainText', function() {
  return function(val) {
    //remove html tags
    var s1 = val.replace(/<\/?[^>]+(>|$)/g, "");

    //translate special symbols
    var translate_re = /&(nbsp|amp|quot|lt|gt);/g;
    var translate = {"nbsp": " ","amp" : "&","quot": "\"","lt"  : "<","gt"  : ">"};
    return ( s1.replace(translate_re, function(match, entity) {
      return translate[entity];
    }) );
  };
});

And how it is being used on HTML page;
{{htmlMessage.body | plainText}}

среда, 18 января 2012 г.

Disabled fields in ExtJS form

If you want to disable input field in your form, don't make it:


disabled: true
In this case value of the field won't be submitted (this is standard
behaviour for HTML forms). Insted of this use: 

readOnly: true,
fieldClass: "x-item-disabled"
 In this case field value will be submitted but field itself will look
 like disabled and will be not editable.