/* MARKUP */ $.fn.uaString_ReadOnly = function(options) { options = $.extend({ bMandatory: true , bToolTip: true , //true, TYPE_OPTIONAL, TYPE_IGNORE bDisabled: false , bReadOnly: false , iMinChars: 10 , //min number of characters iMaxChars: 100 , //max number f characters defaultValue: '' , hint: '' , msg: '' }, options); $.fn.extend(this,this.uaBaseObject({ bMandatory: options.bMandatory, //true, TYPE_OPTIONAL, TYPE_IGNORE bDisabled: options.bDisabled, bReadOnly: options.bReadOnly, defaultValue: options.defaultValue, bToolTip: options.bToolTip, hint: options.hint })); $(this). attr("maxLength",options.iMaxChars). trigger(EV_INIT); this. off(EV_CLEAR). off(EV_SET). off(EV_CHECK_GENERIC_ERRORS). on(EV_CLEAR,function(ev) { ev.stopImmediatePropagation(); $(this).val('').trigger(EV_CLEAR_ERRORS); }). on(EV_SET,function(ev) { ev.stopImmediatePropagation(); $(this).val(ev.uaData.data.label); $(this).data("id",JSON.stringify(ev.uaData.data.id)); }). on(EV_SET_DEFAULT,function(ev) { ev.stopImmediatePropagation(); if(options.bDisabled) { $(this).addClass('uaDisabled'); } else { $(this).removeClass('uaDisabled'); }; $(this).attr({placeholder : options.hint}); $(this).val(options.defaultValue); }). on(EV_CHECK_GENERIC_ERRORS, function(ev) {//check IF errors are possible ev.stopImmediatePropagation(); //clear field before checking $(this).trigger(EV_CLEAR_ERRORS).removeClass('border-danger'); //disabled or readonbly: no errors possible switch($(this).hasClass('uaDisabled') || !!$(this).attr('bReadOnly')) { case true: $(this).attr({'data-bs-original-title':''}); break; default: if(options.bMandatory && !$(this).val().length) { $(this).addClass('border-danger').trigger($.Event(EV_SET_ERROR_MSG,{uaData:{data:{msg:options.msg}}})); }; break; };//switch($(this).hasClass('uaDisabled') || $(this).attr('bReadOnly')!==null) }). on(EV_CHECK_SPECIFIC_ERRORS, function(ev) {//check text length ev.stopImmediatePropagation(); $(this).trigger(EV_CLEAR_ERRORS); if($(this).val().length >=options.iMinChars) return; $(this).trigger($.Event(EV_SET_ERROR_MSG,{uaData:{data:{msg:options.msg}}})); }); this.getSelection = function() {//select vlaue & id return { label: $(this).val(), id: JSON.parse($(this).data("id")) }; }; return $(this); };//uaString