Skip to content

Rating Form Control (v1.12+)

Show basic rating

let dbMasterConfig: T.IDBMasterConfig = {
    form: {
        fields: [
            [{
                label: 'Ratings',
                control: T.EDBMasterFormControl.rating,
                path: 'rating_field',

                ratingSettings: {
                    stars: 10,

                    //     cancelIconHTML: `<img 
                    // src="https://primefaces.org/cdn/primeng/images/demo/rating/cancel.png" 
                    // width="25px" 
                    // height="25px" />`,

                    //     onIconHTML: `<img 
                    // src="https://primefaces.org/cdn/primeng/images/demo/rating/custom-icon-active.png" 
                    // width="25px" 
                    // height="25px" />`,


                    //     offIconHTML: `<img 
                    // src="https://primefaces.org/cdn/primeng/images/demo/rating/custom-icon.png"
                    // width="25px"
                    // height="25px" />`,
                }
            }],
        ]
    }
};

Interface Documentation

export interface IDBMasterConfigFormField {
    /** It is used to find element. */
    hiddenId?: string;
    label?: string;

    /** This text will be displayed under control in small. HTML supported. */
    helpText?: string;

    /** database field name, UI control value will be saved on this property in save/update object. */
    path?: string;

    /** UI control type */
    control?: EDBMasterFormControl;

    /**
     * Default : col-lg mt-4 col-md-{ 12 / ((columns.length === 2 ? 4 : columns.length) / 2) } <br/>
     * It will be applied to parent div which holds UI control in it.
     * */
    cssClassDiv?: string;

    /** if true, that control will take focus automatically. */
    autofocus?: boolean;

    /** if true, control will be disabled. If string provides, it will evaluate that string and enable/disable based on that. */
    disabled?: boolean | string;

    /** if true or undefined, control will be visible. If string provides, it will evaluate that string and make it visible/invisible based on that. */
    visible?: boolean | string;

    /** Generates UI controls. */
    fields?: IDBMasterConfigFormField[][];

    validations?: Pick<IPropertyValidation, 'required'>;
    validationErrors?: {
        required?: string;
    };

    ratingSettings?: {
        /** Advisory information to display in a tooltip on hover. */
        tooltip?: string;

        /** Type of CSS position. */
        tooltipPosition?: 'left' | 'top' | 'bottom' | 'right';
        tooltipStyleClass?: string;

        /** When specified a cancel icon is displayed to allow removing the value. */
        cancel?: boolean;

        /** Style class of the on icon. */
        iconOnClass?: string;

        /** Inline style of the on icon. */
        iconOnStyle?: any;

        /** Style class of the off icon. */
        iconOffClass?: string;

        /** Inline style of the off icon. */
        iconOffStyle?: any;

        /** Style class of the cancel icon. */
        iconCancelClass?: string;

        /** Inline style of the cancel icon. */
        iconCancelStyle?: any;

        /** Number of stars. */
        stars?: number;

        /** cancel rating custom HTML */
        cancelIconHTML?: string;
        onIconHTML?: string;
        offIconHTML?: string;

        jsCode?: {
            /**
             * Available variables:<br/>
             * formData: any = Entire form object<br/>
             * column: IDBMasterConfigFormField = Configuration of that form column. column.dropdownSettings?.dbData?.find will be query to get data. <br/>
             * allDropdownDataMap: {[path: string]: any[]} = Map of all dropdown data<br/>
             * globalData: any = User will send it using SET_GLOBAL_DATA_TO_USE_IN_ANY_SCRIPT event from parent. <br/>
             * utils: any = Common utility functions for user to use. <br/>
             * queryParams: any = Query params received from URL. <br/>
             * config: IDBMasterConfigFormField <br/>
             * event: any <br/>
             */
            appendTo: EDBMasterRatingAppendTo,
            /**
             * // dropdownData is available to use.
             *
             * // Return promise for long awaiting tasks.
             * new Promise(async (resolve, reject) => {
             *     await new Promise(r => setTimeout(r, 3000));
             *     dropdownData[0].name = 'Sample data';
             *     resolve();
             * });
             *
             * // Directly modify data of grid
             * dropdownData[0].name = 'Sample data';
             *
             * // Return function
             * (function setData() { dropdownData[0].name = 'Sample data'; } );
             *
             */
            code: string,
        }[],
    };

}


export interface IPropertyValidation {
    required?: boolean; // Allowed Types : *
    min?: number; // Allowed Types : number | date
    max?: number; // Allowed Types : number | date
    minLength?: number; // Allowed Types : string
    maxLength?: number; // Allowed Types : string
    unique?: boolean;
    email?: boolean; // Allowed Types : string
    validatorFun?: Function;

    /** If value is present it should be from this array. */
    enum?: any[];
}


export enum EDBMasterRatingAppendTo {
    visible = 'visible',
    disabled = 'disabled',
    ngModelChange = 'ngModelChange',
    onRate = 'onRate',
    onCancel = 'onCancel',
    onFocus = 'onFocus',
    onBlur = 'onBlur',
}


export enum EDBMasterFormControl {
    input = 'input',
    inputNumber = 'inputNumber',
    inputMask = 'inputMask',
    inputOtp = 'inputOtp',
    password = 'password',
    date_picker = 'date_picker',
    textarea = 'textarea',
    checkbox = 'checkbox',
    radio = 'radio',
    color_picker = 'color_picker',
    dropdown = 'dropdown',
    auto_complete = 'auto_complete',
    multi_select = 'multi_select',
    file_upload = 'file_upload',
    grid = 'grid',
    divider = 'divider',
    rating = 'rating',
    knob = 'knob',

    // Field holder controls
    accordion = 'accordion',
    tab_view = 'tab_view',

    // utility controls
    button = 'button',
    image = 'image',
    customHTML = 'customHTML',
}

export enum EDBMasterCustomActionButtonAppendTo {
    click = 'click',
}