vue_jqxvalidator.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div v-bind:id="id">
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. import '../jqwidgets/jqxcore.js';
  8. import '../jqwidgets/jqxvalidator.js';
  9. export default {
  10. props: {
  11. arrow: Boolean,
  12. animation: String,
  13. animationDuration: Number,
  14. closeOnClick: Boolean,
  15. focus: Boolean,
  16. hintType: String,
  17. onError: Function,
  18. onSuccess: Function,
  19. position: String,
  20. rules: Array,
  21. rtl: Boolean,
  22. autoCreate: {
  23. default: true,
  24. type: Boolean
  25. }
  26. },
  27. created: function () {
  28. this.id = 'jqxValidator' + JQXLite.generateID();
  29. this.componentSelector = '#' + this.id;
  30. },
  31. mounted: function () {
  32. if (this.autoCreate) this.__createComponent__();
  33. },
  34. methods: {
  35. createComponent: function (options) {
  36. if (!this.autoCreate) this.__createComponent__(options)
  37. else console.warn('Component is already created! If you want to use createComponent, please set "autoCreate" property to "false".');
  38. },
  39. setOptions: function (options) {
  40. JQXLite(this.componentSelector).jqxValidator(options);
  41. },
  42. getOptions: function () {
  43. const usedProps = Object.keys(this.__manageProps__());
  44. const resultToReturn = {};
  45. for (let i = 0; i < usedProps.length; i++) {
  46. resultToReturn[usedProps[i]] = JQXLite(this.componentSelector).jqxValidator(usedProps[i]);
  47. }
  48. return resultToReturn;
  49. },
  50. hideHint: function(id) {
  51. JQXLite(this.componentSelector).jqxValidator('hideHint', id);
  52. },
  53. hide: function() {
  54. JQXLite(this.componentSelector).jqxValidator('hide');
  55. },
  56. updatePosition: function() {
  57. JQXLite(this.componentSelector).jqxValidator('updatePosition');
  58. },
  59. validate: function(htmlElement) {
  60. JQXLite(this.componentSelector).jqxValidator('validate', htmlElement);
  61. },
  62. validateInput: function(id) {
  63. JQXLite(this.componentSelector).jqxValidator('validateInput', id);
  64. },
  65. _arrow: function(arg) {
  66. if (arg !== undefined) {
  67. JQXLite(this.componentSelector).jqxValidator('arrow', arg)
  68. } else {
  69. return JQXLite(this.componentSelector).jqxValidator('arrow');
  70. }
  71. },
  72. _animation: function(arg) {
  73. if (arg !== undefined) {
  74. JQXLite(this.componentSelector).jqxValidator('animation', arg)
  75. } else {
  76. return JQXLite(this.componentSelector).jqxValidator('animation');
  77. }
  78. },
  79. _animationDuration: function(arg) {
  80. if (arg !== undefined) {
  81. JQXLite(this.componentSelector).jqxValidator('animationDuration', arg)
  82. } else {
  83. return JQXLite(this.componentSelector).jqxValidator('animationDuration');
  84. }
  85. },
  86. _closeOnClick: function(arg) {
  87. if (arg !== undefined) {
  88. JQXLite(this.componentSelector).jqxValidator('closeOnClick', arg)
  89. } else {
  90. return JQXLite(this.componentSelector).jqxValidator('closeOnClick');
  91. }
  92. },
  93. _focus: function(arg) {
  94. if (arg !== undefined) {
  95. JQXLite(this.componentSelector).jqxValidator('focus', arg)
  96. } else {
  97. return JQXLite(this.componentSelector).jqxValidator('focus');
  98. }
  99. },
  100. _hintType: function(arg) {
  101. if (arg !== undefined) {
  102. JQXLite(this.componentSelector).jqxValidator('hintType', arg)
  103. } else {
  104. return JQXLite(this.componentSelector).jqxValidator('hintType');
  105. }
  106. },
  107. _onError: function(arg) {
  108. if (arg !== undefined) {
  109. JQXLite(this.componentSelector).jqxValidator('onError', arg)
  110. } else {
  111. return JQXLite(this.componentSelector).jqxValidator('onError');
  112. }
  113. },
  114. _onSuccess: function(arg) {
  115. if (arg !== undefined) {
  116. JQXLite(this.componentSelector).jqxValidator('onSuccess', arg)
  117. } else {
  118. return JQXLite(this.componentSelector).jqxValidator('onSuccess');
  119. }
  120. },
  121. _position: function(arg) {
  122. if (arg !== undefined) {
  123. JQXLite(this.componentSelector).jqxValidator('position', arg)
  124. } else {
  125. return JQXLite(this.componentSelector).jqxValidator('position');
  126. }
  127. },
  128. _rules: function(arg) {
  129. if (arg !== undefined) {
  130. JQXLite(this.componentSelector).jqxValidator('rules', arg)
  131. } else {
  132. return JQXLite(this.componentSelector).jqxValidator('rules');
  133. }
  134. },
  135. _rtl: function(arg) {
  136. if (arg !== undefined) {
  137. JQXLite(this.componentSelector).jqxValidator('rtl', arg)
  138. } else {
  139. return JQXLite(this.componentSelector).jqxValidator('rtl');
  140. }
  141. },
  142. __createComponent__: function (options) {
  143. let widgetOptions;
  144. options ? widgetOptions = options : widgetOptions = this.__manageProps__();
  145. JQXLite(this.componentSelector).jqxValidator(widgetOptions);
  146. this.__extendProps__();
  147. this.__wireEvents__();
  148. },
  149. __manageProps__: function () {
  150. const widgetProps = ['arrow','animation','animationDuration','closeOnClick','focus','hintType','onError','onSuccess','position','rules','rtl'];
  151. const componentProps = this.$options.propsData;
  152. let options = {};
  153. for (let prop in componentProps) {
  154. if (widgetProps.indexOf(prop) !== -1) {
  155. options[prop] = componentProps[prop];
  156. }
  157. }
  158. return options;
  159. },
  160. __extendProps__: function () {
  161. const that = this;
  162. Object.defineProperty(that, 'arrow', {
  163. get: function() {
  164. return that._arrow();
  165. },
  166. set: function(newValue) {
  167. that._arrow(newValue);
  168. },
  169. enumerable: true,
  170. configurable: true
  171. });
  172. Object.defineProperty(that, 'animation', {
  173. get: function() {
  174. return that._animation();
  175. },
  176. set: function(newValue) {
  177. that._animation(newValue);
  178. },
  179. enumerable: true,
  180. configurable: true
  181. });
  182. Object.defineProperty(that, 'animationDuration', {
  183. get: function() {
  184. return that._animationDuration();
  185. },
  186. set: function(newValue) {
  187. that._animationDuration(newValue);
  188. },
  189. enumerable: true,
  190. configurable: true
  191. });
  192. Object.defineProperty(that, 'closeOnClick', {
  193. get: function() {
  194. return that._closeOnClick();
  195. },
  196. set: function(newValue) {
  197. that._closeOnClick(newValue);
  198. },
  199. enumerable: true,
  200. configurable: true
  201. });
  202. Object.defineProperty(that, 'focus', {
  203. get: function() {
  204. return that._focus();
  205. },
  206. set: function(newValue) {
  207. that._focus(newValue);
  208. },
  209. enumerable: true,
  210. configurable: true
  211. });
  212. Object.defineProperty(that, 'hintType', {
  213. get: function() {
  214. return that._hintType();
  215. },
  216. set: function(newValue) {
  217. that._hintType(newValue);
  218. },
  219. enumerable: true,
  220. configurable: true
  221. });
  222. Object.defineProperty(that, 'onError', {
  223. get: function() {
  224. return that._onError();
  225. },
  226. set: function(newValue) {
  227. that._onError(newValue);
  228. },
  229. enumerable: true,
  230. configurable: true
  231. });
  232. Object.defineProperty(that, 'onSuccess', {
  233. get: function() {
  234. return that._onSuccess();
  235. },
  236. set: function(newValue) {
  237. that._onSuccess(newValue);
  238. },
  239. enumerable: true,
  240. configurable: true
  241. });
  242. Object.defineProperty(that, 'position', {
  243. get: function() {
  244. return that._position();
  245. },
  246. set: function(newValue) {
  247. that._position(newValue);
  248. },
  249. enumerable: true,
  250. configurable: true
  251. });
  252. Object.defineProperty(that, 'rules', {
  253. get: function() {
  254. return that._rules();
  255. },
  256. set: function(newValue) {
  257. that._rules(newValue);
  258. },
  259. enumerable: true,
  260. configurable: true
  261. });
  262. Object.defineProperty(that, 'rtl', {
  263. get: function() {
  264. return that._rtl();
  265. },
  266. set: function(newValue) {
  267. that._rtl(newValue);
  268. },
  269. enumerable: true,
  270. configurable: true
  271. });
  272. },
  273. __wireEvents__: function () {
  274. const that = this;
  275. JQXLite(this.componentSelector).on('validationError', function (event) { that.$emit('validationError', event); });
  276. JQXLite(this.componentSelector).on('validationSuccess', function (event) { that.$emit('validationSuccess', event); });
  277. }
  278. }
  279. }
  280. </script>