To create custom field type you have to create field type in clients base directory. Here is path and code for custom field type
custom/clients/base/fields/my-field/details.hbs
{{#if value}}
 
<div class=”ellipsis_inline” data-placement=”bottom” style=”background:blue; color:white”>
 
    {{value}}
 
</div>
 
{{/if}}
   and one more file for edit view
custom/clients/base/fields/my-field/edit.hbs
<input type=”text” name=”{{name}}” value=”{{value}}”{{#if def.len}} maxlength=”{{def.len}}”{{/if}}{{#if def.placeholder}} placeholder=”{{str def.placeholder this.model.module}}”{{/if}} class=”inherit-width”>
 
<p class=”help-block”></p>
   and one more file for edit view
custom/clients/base/fields/my-field/list.hbs
 {{#if def.link}}
<a href=”{{#if def.events}} javascript:void(0);{{else}}{{href}}{{/if}}”>{{value}}</a>
{{else}}
{{value}}
{{/if}}
{{#with model.attributes}}
{{name}}
{{/with}}
one js file to handle events is also required
custom/clients/base/fields/my-field/my-field.hbs
 
({
 
    _render: function() {
 
        var action = “view”;
 
        if (this.def.link && this.def.route) {
 
            action = this.def.route.action;
 
        }
 
        if (!app.acl.hasAccessToModel(action, this.model)) {
 
            this.def.link = false;
 
        }
 
        if (this.def.link) {
 
            this.href = this.buildHref();
 
        }
 
        app.view.Field.prototype._render.call(this);
 
    },
 
 
 
    /**
 
     * Takes care of building href for when there’s a def.link and also if is
 
     * bwc enabled.
 
     *
 
     * Deprecated functionality:
 
     * If `this.def.bwcLink` is set to `true` on metadata, we force the href
 
     * to be in BWC.
 
     */
 
    buildHref: function() {
 
        var defRoute = this.def.route ? this.def.route : {},
 
            module = this.model.module || this.context.get(‘module’);
 
        return ‘#’ + app.router.buildRoute(module, this.model.id, defRoute.action, this.def.bwcLink);
 
    },
 
    /**
 
     * Trim whitespace from value if it is a String
 
     * @param value
 
     * @return {*}
 
     */
 
    unformat: function(value){
 
        return _.isString(value) ? value.trim() : value;
 
    }
 
})

Leave a Reply

Your email address will not be published. Required fields are marked *