radio-group.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. /*!
  13. * devextreme-angular
  14. * Version: 19.1.16
  15. * Build date: Tue Oct 18 2022
  16. *
  17. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  18. *
  19. * This software may be modified and distributed under the terms
  20. * of the MIT license. See the LICENSE file in the root of the project for details.
  21. *
  22. * https://github.com/DevExpress/devextreme-angular
  23. */
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var platform_browser_1 = require("@angular/platform-browser");
  26. var platform_browser_2 = require("@angular/platform-browser");
  27. var core_1 = require("@angular/core");
  28. var radio_group_1 = require("devextreme/ui/radio_group");
  29. var forms_1 = require("@angular/forms");
  30. var component_1 = require("../core/component");
  31. var template_host_1 = require("../core/template-host");
  32. var integration_1 = require("../core/integration");
  33. var template_1 = require("../core/template");
  34. var nested_option_1 = require("../core/nested-option");
  35. var watcher_helper_1 = require("../core/watcher-helper");
  36. var iterable_differ_helper_1 = require("../core/iterable-differ-helper");
  37. var item_dxi_1 = require("./nested/item-dxi");
  38. var item_dxi_2 = require("./nested/item-dxi");
  39. var CUSTOM_VALUE_ACCESSOR_PROVIDER = {
  40. provide: forms_1.NG_VALUE_ACCESSOR,
  41. useExisting: core_1.forwardRef(function () { return DxRadioGroupComponent; }),
  42. multi: true
  43. };
  44. /**
  45. * The RadioGroup is a widget that contains a set of radio buttons and allows an end user to make a single selection from the set.
  46. */
  47. var DxRadioGroupComponent = (function (_super) {
  48. __extends(DxRadioGroupComponent, _super);
  49. function DxRadioGroupComponent(elementRef, ngZone, templateHost, _watcherHelper, _idh, optionHost, transferState, platformId) {
  50. var _this = _super.call(this, elementRef, ngZone, templateHost, _watcherHelper, transferState, platformId) || this;
  51. _this._watcherHelper = _watcherHelper;
  52. _this._idh = _idh;
  53. _this.touched = function (_) { };
  54. _this._createEventEmitters([
  55. { subscribe: 'contentReady', emit: 'onContentReady' },
  56. { subscribe: 'disposing', emit: 'onDisposing' },
  57. { subscribe: 'initialized', emit: 'onInitialized' },
  58. { subscribe: 'optionChanged', emit: 'onOptionChanged' },
  59. { subscribe: 'valueChanged', emit: 'onValueChanged' },
  60. { emit: 'accessKeyChange' },
  61. { emit: 'activeStateEnabledChange' },
  62. { emit: 'dataSourceChange' },
  63. { emit: 'disabledChange' },
  64. { emit: 'displayExprChange' },
  65. { emit: 'elementAttrChange' },
  66. { emit: 'focusStateEnabledChange' },
  67. { emit: 'heightChange' },
  68. { emit: 'hintChange' },
  69. { emit: 'hoverStateEnabledChange' },
  70. { emit: 'isValidChange' },
  71. { emit: 'itemsChange' },
  72. { emit: 'itemTemplateChange' },
  73. { emit: 'layoutChange' },
  74. { emit: 'nameChange' },
  75. { emit: 'readOnlyChange' },
  76. { emit: 'rtlEnabledChange' },
  77. { emit: 'tabIndexChange' },
  78. { emit: 'validationErrorChange' },
  79. { emit: 'validationMessageModeChange' },
  80. { emit: 'valueChange' },
  81. { emit: 'valueExprChange' },
  82. { emit: 'visibleChange' },
  83. { emit: 'widthChange' },
  84. { emit: 'onBlur' }
  85. ]);
  86. _this._idh.setHost(_this);
  87. optionHost.setHost(_this);
  88. return _this;
  89. }
  90. Object.defineProperty(DxRadioGroupComponent.prototype, "accessKey", {
  91. get: /**
  92. * Specifies the shortcut key that sets focus on the widget.
  93. */
  94. function () {
  95. return this._getOption('accessKey');
  96. },
  97. set: function (value) {
  98. this._setOption('accessKey', value);
  99. },
  100. enumerable: true,
  101. configurable: true
  102. });
  103. Object.defineProperty(DxRadioGroupComponent.prototype, "activeStateEnabled", {
  104. get: /**
  105. * Specifies whether or not the widget changes its state when interacting with a user.
  106. */
  107. function () {
  108. return this._getOption('activeStateEnabled');
  109. },
  110. set: function (value) {
  111. this._setOption('activeStateEnabled', value);
  112. },
  113. enumerable: true,
  114. configurable: true
  115. });
  116. Object.defineProperty(DxRadioGroupComponent.prototype, "dataSource", {
  117. get: /**
  118. * Binds the widget to data.
  119. */
  120. function () {
  121. return this._getOption('dataSource');
  122. },
  123. set: function (value) {
  124. this._setOption('dataSource', value);
  125. },
  126. enumerable: true,
  127. configurable: true
  128. });
  129. Object.defineProperty(DxRadioGroupComponent.prototype, "disabled", {
  130. get: /**
  131. * Specifies whether the widget responds to user interaction.
  132. */
  133. function () {
  134. return this._getOption('disabled');
  135. },
  136. set: function (value) {
  137. this._setOption('disabled', value);
  138. },
  139. enumerable: true,
  140. configurable: true
  141. });
  142. Object.defineProperty(DxRadioGroupComponent.prototype, "displayExpr", {
  143. get: /**
  144. * Specifies the data field whose values should be displayed.
  145. */
  146. function () {
  147. return this._getOption('displayExpr');
  148. },
  149. set: function (value) {
  150. this._setOption('displayExpr', value);
  151. },
  152. enumerable: true,
  153. configurable: true
  154. });
  155. Object.defineProperty(DxRadioGroupComponent.prototype, "elementAttr", {
  156. get: /**
  157. * Specifies the attributes to be attached to the widget's root element.
  158. */
  159. function () {
  160. return this._getOption('elementAttr');
  161. },
  162. set: function (value) {
  163. this._setOption('elementAttr', value);
  164. },
  165. enumerable: true,
  166. configurable: true
  167. });
  168. Object.defineProperty(DxRadioGroupComponent.prototype, "focusStateEnabled", {
  169. get: /**
  170. * Specifies whether the widget can be focused using keyboard navigation.
  171. */
  172. function () {
  173. return this._getOption('focusStateEnabled');
  174. },
  175. set: function (value) {
  176. this._setOption('focusStateEnabled', value);
  177. },
  178. enumerable: true,
  179. configurable: true
  180. });
  181. Object.defineProperty(DxRadioGroupComponent.prototype, "height", {
  182. get: /**
  183. * Specifies the widget's height.
  184. */
  185. function () {
  186. return this._getOption('height');
  187. },
  188. set: function (value) {
  189. this._setOption('height', value);
  190. },
  191. enumerable: true,
  192. configurable: true
  193. });
  194. Object.defineProperty(DxRadioGroupComponent.prototype, "hint", {
  195. get: /**
  196. * Specifies text for a hint that appears when a user pauses on the widget.
  197. */
  198. function () {
  199. return this._getOption('hint');
  200. },
  201. set: function (value) {
  202. this._setOption('hint', value);
  203. },
  204. enumerable: true,
  205. configurable: true
  206. });
  207. Object.defineProperty(DxRadioGroupComponent.prototype, "hoverStateEnabled", {
  208. get: /**
  209. * Specifies whether the widget changes its state when a user pauses on it.
  210. */
  211. function () {
  212. return this._getOption('hoverStateEnabled');
  213. },
  214. set: function (value) {
  215. this._setOption('hoverStateEnabled', value);
  216. },
  217. enumerable: true,
  218. configurable: true
  219. });
  220. Object.defineProperty(DxRadioGroupComponent.prototype, "isValid", {
  221. get: /**
  222. * Specifies whether the editor's value is valid.
  223. */
  224. function () {
  225. return this._getOption('isValid');
  226. },
  227. set: function (value) {
  228. this._setOption('isValid', value);
  229. },
  230. enumerable: true,
  231. configurable: true
  232. });
  233. Object.defineProperty(DxRadioGroupComponent.prototype, "items", {
  234. get: /**
  235. * An array of items displayed by the widget.
  236. */
  237. function () {
  238. return this._getOption('items');
  239. },
  240. set: function (value) {
  241. this._setOption('items', value);
  242. },
  243. enumerable: true,
  244. configurable: true
  245. });
  246. Object.defineProperty(DxRadioGroupComponent.prototype, "itemTemplate", {
  247. get: /**
  248. * Specifies a custom template for items.
  249. */
  250. function () {
  251. return this._getOption('itemTemplate');
  252. },
  253. set: function (value) {
  254. this._setOption('itemTemplate', value);
  255. },
  256. enumerable: true,
  257. configurable: true
  258. });
  259. Object.defineProperty(DxRadioGroupComponent.prototype, "layout", {
  260. get: /**
  261. * Specifies the radio group layout.
  262. */
  263. function () {
  264. return this._getOption('layout');
  265. },
  266. set: function (value) {
  267. this._setOption('layout', value);
  268. },
  269. enumerable: true,
  270. configurable: true
  271. });
  272. Object.defineProperty(DxRadioGroupComponent.prototype, "name", {
  273. get: /**
  274. * The value to be assigned to the `name` attribute of the underlying HTML element.
  275. */
  276. function () {
  277. return this._getOption('name');
  278. },
  279. set: function (value) {
  280. this._setOption('name', value);
  281. },
  282. enumerable: true,
  283. configurable: true
  284. });
  285. Object.defineProperty(DxRadioGroupComponent.prototype, "readOnly", {
  286. get: /**
  287. * Specifies whether the editor is read-only.
  288. */
  289. function () {
  290. return this._getOption('readOnly');
  291. },
  292. set: function (value) {
  293. this._setOption('readOnly', value);
  294. },
  295. enumerable: true,
  296. configurable: true
  297. });
  298. Object.defineProperty(DxRadioGroupComponent.prototype, "rtlEnabled", {
  299. get: /**
  300. * Switches the widget to a right-to-left representation.
  301. */
  302. function () {
  303. return this._getOption('rtlEnabled');
  304. },
  305. set: function (value) {
  306. this._setOption('rtlEnabled', value);
  307. },
  308. enumerable: true,
  309. configurable: true
  310. });
  311. Object.defineProperty(DxRadioGroupComponent.prototype, "tabIndex", {
  312. get: /**
  313. * Specifies the number of the element when the Tab key is used for navigating.
  314. */
  315. function () {
  316. return this._getOption('tabIndex');
  317. },
  318. set: function (value) {
  319. this._setOption('tabIndex', value);
  320. },
  321. enumerable: true,
  322. configurable: true
  323. });
  324. Object.defineProperty(DxRadioGroupComponent.prototype, "validationError", {
  325. get: /**
  326. * Specifies information on the validation error when using a custom validation engine. Should be changed at runtime along with the isValid option.
  327. */
  328. function () {
  329. return this._getOption('validationError');
  330. },
  331. set: function (value) {
  332. this._setOption('validationError', value);
  333. },
  334. enumerable: true,
  335. configurable: true
  336. });
  337. Object.defineProperty(DxRadioGroupComponent.prototype, "validationMessageMode", {
  338. get: /**
  339. * Specifies how the message about the validation rules that are not satisfied by this editor's value is displayed.
  340. */
  341. function () {
  342. return this._getOption('validationMessageMode');
  343. },
  344. set: function (value) {
  345. this._setOption('validationMessageMode', value);
  346. },
  347. enumerable: true,
  348. configurable: true
  349. });
  350. Object.defineProperty(DxRadioGroupComponent.prototype, "value", {
  351. get: /**
  352. * Specifies the widget's value.
  353. */
  354. function () {
  355. return this._getOption('value');
  356. },
  357. set: function (value) {
  358. this._setOption('value', value);
  359. },
  360. enumerable: true,
  361. configurable: true
  362. });
  363. Object.defineProperty(DxRadioGroupComponent.prototype, "valueExpr", {
  364. get: /**
  365. * Specifies which data field provides unique values to the widget's value.
  366. */
  367. function () {
  368. return this._getOption('valueExpr');
  369. },
  370. set: function (value) {
  371. this._setOption('valueExpr', value);
  372. },
  373. enumerable: true,
  374. configurable: true
  375. });
  376. Object.defineProperty(DxRadioGroupComponent.prototype, "visible", {
  377. get: /**
  378. * Specifies whether the widget is visible.
  379. */
  380. function () {
  381. return this._getOption('visible');
  382. },
  383. set: function (value) {
  384. this._setOption('visible', value);
  385. },
  386. enumerable: true,
  387. configurable: true
  388. });
  389. Object.defineProperty(DxRadioGroupComponent.prototype, "width", {
  390. get: /**
  391. * Specifies the widget's width.
  392. */
  393. function () {
  394. return this._getOption('width');
  395. },
  396. set: function (value) {
  397. this._setOption('width', value);
  398. },
  399. enumerable: true,
  400. configurable: true
  401. });
  402. DxRadioGroupComponent.prototype.change = function (_) { };
  403. Object.defineProperty(DxRadioGroupComponent.prototype, "itemsChildren", {
  404. get: function () {
  405. return this._getOption('items');
  406. },
  407. set: function (value) {
  408. this.setChildren('items', value);
  409. },
  410. enumerable: true,
  411. configurable: true
  412. });
  413. DxRadioGroupComponent.prototype._createInstance = function (element, options) {
  414. return new radio_group_1.default(element, options);
  415. };
  416. DxRadioGroupComponent.prototype.writeValue = function (value) {
  417. this.eventHelper.lockedValueChangeEvent = true;
  418. this.value = value;
  419. this.eventHelper.lockedValueChangeEvent = false;
  420. };
  421. DxRadioGroupComponent.prototype.setDisabledState = function (isDisabled) {
  422. this.disabled = isDisabled;
  423. };
  424. DxRadioGroupComponent.prototype.registerOnChange = function (fn) { this.change = fn; };
  425. DxRadioGroupComponent.prototype.registerOnTouched = function (fn) { this.touched = fn; };
  426. DxRadioGroupComponent.prototype._createWidget = function (element) {
  427. var _this = this;
  428. _super.prototype._createWidget.call(this, element);
  429. this.instance.on('focusOut', function (e) {
  430. _this.eventHelper.fireNgEvent('onBlur', [e]);
  431. });
  432. };
  433. DxRadioGroupComponent.prototype.ngOnDestroy = function () {
  434. this._destroyWidget();
  435. };
  436. DxRadioGroupComponent.prototype.ngOnChanges = function (changes) {
  437. _super.prototype.ngOnChanges.call(this, changes);
  438. this.setupChanges('dataSource', changes);
  439. this.setupChanges('items', changes);
  440. };
  441. DxRadioGroupComponent.prototype.setupChanges = function (prop, changes) {
  442. if (!(prop in this._optionsToUpdate)) {
  443. this._idh.setup(prop, changes);
  444. }
  445. };
  446. DxRadioGroupComponent.prototype.ngDoCheck = function () {
  447. this._idh.doCheck('dataSource');
  448. this._idh.doCheck('items');
  449. this._watcherHelper.checkWatchers();
  450. _super.prototype.ngDoCheck.call(this);
  451. _super.prototype.clearChangedOptions.call(this);
  452. };
  453. DxRadioGroupComponent.prototype._setOption = function (name, value) {
  454. var isSetup = this._idh.setupSingle(name, value);
  455. var isChanged = this._idh.getChanges(name, value) !== null;
  456. if (isSetup || isChanged) {
  457. _super.prototype._setOption.call(this, name, value);
  458. }
  459. };
  460. DxRadioGroupComponent.decorators = [
  461. { type: core_1.Component, args: [{
  462. selector: 'dx-radio-group',
  463. template: '',
  464. providers: [
  465. template_host_1.DxTemplateHost,
  466. watcher_helper_1.WatcherHelper,
  467. CUSTOM_VALUE_ACCESSOR_PROVIDER,
  468. nested_option_1.NestedOptionHost,
  469. iterable_differ_helper_1.IterableDifferHelper
  470. ]
  471. },] },
  472. ];
  473. /** @nocollapse */
  474. DxRadioGroupComponent.ctorParameters = function () { return [
  475. { type: core_1.ElementRef, },
  476. { type: core_1.NgZone, },
  477. { type: template_host_1.DxTemplateHost, },
  478. { type: watcher_helper_1.WatcherHelper, },
  479. { type: iterable_differ_helper_1.IterableDifferHelper, },
  480. { type: nested_option_1.NestedOptionHost, },
  481. { type: platform_browser_2.TransferState, },
  482. { type: undefined, decorators: [{ type: core_1.Inject, args: [core_1.PLATFORM_ID,] },] },
  483. ]; };
  484. DxRadioGroupComponent.propDecorators = {
  485. "accessKey": [{ type: core_1.Input },],
  486. "activeStateEnabled": [{ type: core_1.Input },],
  487. "dataSource": [{ type: core_1.Input },],
  488. "disabled": [{ type: core_1.Input },],
  489. "displayExpr": [{ type: core_1.Input },],
  490. "elementAttr": [{ type: core_1.Input },],
  491. "focusStateEnabled": [{ type: core_1.Input },],
  492. "height": [{ type: core_1.Input },],
  493. "hint": [{ type: core_1.Input },],
  494. "hoverStateEnabled": [{ type: core_1.Input },],
  495. "isValid": [{ type: core_1.Input },],
  496. "items": [{ type: core_1.Input },],
  497. "itemTemplate": [{ type: core_1.Input },],
  498. "layout": [{ type: core_1.Input },],
  499. "name": [{ type: core_1.Input },],
  500. "readOnly": [{ type: core_1.Input },],
  501. "rtlEnabled": [{ type: core_1.Input },],
  502. "tabIndex": [{ type: core_1.Input },],
  503. "validationError": [{ type: core_1.Input },],
  504. "validationMessageMode": [{ type: core_1.Input },],
  505. "value": [{ type: core_1.Input },],
  506. "valueExpr": [{ type: core_1.Input },],
  507. "visible": [{ type: core_1.Input },],
  508. "width": [{ type: core_1.Input },],
  509. "onContentReady": [{ type: core_1.Output },],
  510. "onDisposing": [{ type: core_1.Output },],
  511. "onInitialized": [{ type: core_1.Output },],
  512. "onOptionChanged": [{ type: core_1.Output },],
  513. "onValueChanged": [{ type: core_1.Output },],
  514. "accessKeyChange": [{ type: core_1.Output },],
  515. "activeStateEnabledChange": [{ type: core_1.Output },],
  516. "dataSourceChange": [{ type: core_1.Output },],
  517. "disabledChange": [{ type: core_1.Output },],
  518. "displayExprChange": [{ type: core_1.Output },],
  519. "elementAttrChange": [{ type: core_1.Output },],
  520. "focusStateEnabledChange": [{ type: core_1.Output },],
  521. "heightChange": [{ type: core_1.Output },],
  522. "hintChange": [{ type: core_1.Output },],
  523. "hoverStateEnabledChange": [{ type: core_1.Output },],
  524. "isValidChange": [{ type: core_1.Output },],
  525. "itemsChange": [{ type: core_1.Output },],
  526. "itemTemplateChange": [{ type: core_1.Output },],
  527. "layoutChange": [{ type: core_1.Output },],
  528. "nameChange": [{ type: core_1.Output },],
  529. "readOnlyChange": [{ type: core_1.Output },],
  530. "rtlEnabledChange": [{ type: core_1.Output },],
  531. "tabIndexChange": [{ type: core_1.Output },],
  532. "validationErrorChange": [{ type: core_1.Output },],
  533. "validationMessageModeChange": [{ type: core_1.Output },],
  534. "valueChange": [{ type: core_1.Output },],
  535. "valueExprChange": [{ type: core_1.Output },],
  536. "visibleChange": [{ type: core_1.Output },],
  537. "widthChange": [{ type: core_1.Output },],
  538. "onBlur": [{ type: core_1.Output },],
  539. "change": [{ type: core_1.HostListener, args: ['valueChange', ['$event'],] },],
  540. "touched": [{ type: core_1.HostListener, args: ['onBlur', ['$event'],] },],
  541. "itemsChildren": [{ type: core_1.ContentChildren, args: [item_dxi_2.DxiItemComponent,] },],
  542. };
  543. return DxRadioGroupComponent;
  544. }(component_1.DxComponent));
  545. exports.DxRadioGroupComponent = DxRadioGroupComponent;
  546. var DxRadioGroupModule = (function () {
  547. function DxRadioGroupModule() {
  548. }
  549. DxRadioGroupModule.decorators = [
  550. { type: core_1.NgModule, args: [{
  551. imports: [
  552. item_dxi_1.DxiItemModule,
  553. integration_1.DxIntegrationModule,
  554. template_1.DxTemplateModule,
  555. platform_browser_1.BrowserTransferStateModule
  556. ],
  557. declarations: [
  558. DxRadioGroupComponent
  559. ],
  560. exports: [
  561. DxRadioGroupComponent,
  562. item_dxi_1.DxiItemModule,
  563. template_1.DxTemplateModule
  564. ]
  565. },] },
  566. ];
  567. return DxRadioGroupModule;
  568. }());
  569. exports.DxRadioGroupModule = DxRadioGroupModule;
  570. //# sourceMappingURL=radio-group.js.map