| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <template>
- <div v-bind:id="id">
- <slot></slot>
- </div>
- </template>
- <script>
- import '../jqwidgets/jqxcore.js';
- import '../jqwidgets/jqxvalidator.js';
- export default {
- props: {
- arrow: Boolean,
- animation: String,
- animationDuration: Number,
- closeOnClick: Boolean,
- focus: Boolean,
- hintType: String,
- onError: Function,
- onSuccess: Function,
- position: String,
- rules: Array,
- rtl: Boolean,
- autoCreate: {
- default: true,
- type: Boolean
- }
- },
- created: function () {
- this.id = 'jqxValidator' + JQXLite.generateID();
- this.componentSelector = '#' + this.id;
- },
- mounted: function () {
- if (this.autoCreate) this.__createComponent__();
- },
- methods: {
- createComponent: function (options) {
- if (!this.autoCreate) this.__createComponent__(options)
- else console.warn('Component is already created! If you want to use createComponent, please set "autoCreate" property to "false".');
- },
- setOptions: function (options) {
- JQXLite(this.componentSelector).jqxValidator(options);
- },
- getOptions: function () {
- const usedProps = Object.keys(this.__manageProps__());
- const resultToReturn = {};
- for (let i = 0; i < usedProps.length; i++) {
- resultToReturn[usedProps[i]] = JQXLite(this.componentSelector).jqxValidator(usedProps[i]);
- }
- return resultToReturn;
- },
- hideHint: function(id) {
- JQXLite(this.componentSelector).jqxValidator('hideHint', id);
- },
- hide: function() {
- JQXLite(this.componentSelector).jqxValidator('hide');
- },
- updatePosition: function() {
- JQXLite(this.componentSelector).jqxValidator('updatePosition');
- },
- validate: function(htmlElement) {
- JQXLite(this.componentSelector).jqxValidator('validate', htmlElement);
- },
- validateInput: function(id) {
- JQXLite(this.componentSelector).jqxValidator('validateInput', id);
- },
- _arrow: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('arrow', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('arrow');
- }
- },
- _animation: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('animation', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('animation');
- }
- },
- _animationDuration: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('animationDuration', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('animationDuration');
- }
- },
- _closeOnClick: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('closeOnClick', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('closeOnClick');
- }
- },
- _focus: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('focus', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('focus');
- }
- },
- _hintType: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('hintType', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('hintType');
- }
- },
- _onError: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('onError', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('onError');
- }
- },
- _onSuccess: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('onSuccess', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('onSuccess');
- }
- },
- _position: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('position', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('position');
- }
- },
- _rules: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('rules', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('rules');
- }
- },
- _rtl: function(arg) {
- if (arg !== undefined) {
- JQXLite(this.componentSelector).jqxValidator('rtl', arg)
- } else {
- return JQXLite(this.componentSelector).jqxValidator('rtl');
- }
- },
- __createComponent__: function (options) {
- let widgetOptions;
- options ? widgetOptions = options : widgetOptions = this.__manageProps__();
- JQXLite(this.componentSelector).jqxValidator(widgetOptions);
- this.__extendProps__();
- this.__wireEvents__();
- },
- __manageProps__: function () {
- const widgetProps = ['arrow','animation','animationDuration','closeOnClick','focus','hintType','onError','onSuccess','position','rules','rtl'];
- const componentProps = this.$options.propsData;
- let options = {};
- for (let prop in componentProps) {
- if (widgetProps.indexOf(prop) !== -1) {
- options[prop] = componentProps[prop];
- }
- }
- return options;
- },
- __extendProps__: function () {
- const that = this;
- Object.defineProperty(that, 'arrow', {
- get: function() {
- return that._arrow();
- },
- set: function(newValue) {
- that._arrow(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'animation', {
- get: function() {
- return that._animation();
- },
- set: function(newValue) {
- that._animation(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'animationDuration', {
- get: function() {
- return that._animationDuration();
- },
- set: function(newValue) {
- that._animationDuration(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'closeOnClick', {
- get: function() {
- return that._closeOnClick();
- },
- set: function(newValue) {
- that._closeOnClick(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'focus', {
- get: function() {
- return that._focus();
- },
- set: function(newValue) {
- that._focus(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'hintType', {
- get: function() {
- return that._hintType();
- },
- set: function(newValue) {
- that._hintType(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'onError', {
- get: function() {
- return that._onError();
- },
- set: function(newValue) {
- that._onError(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'onSuccess', {
- get: function() {
- return that._onSuccess();
- },
- set: function(newValue) {
- that._onSuccess(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'position', {
- get: function() {
- return that._position();
- },
- set: function(newValue) {
- that._position(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'rules', {
- get: function() {
- return that._rules();
- },
- set: function(newValue) {
- that._rules(newValue);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(that, 'rtl', {
- get: function() {
- return that._rtl();
- },
- set: function(newValue) {
- that._rtl(newValue);
- },
- enumerable: true,
- configurable: true
- });
- },
- __wireEvents__: function () {
- const that = this;
- JQXLite(this.componentSelector).on('validationError', function (event) { that.$emit('validationError', event); });
- JQXLite(this.componentSelector).on('validationSuccess', function (event) { that.$emit('validationSuccess', event); });
- }
- }
- }
- </script>
|