@yuneta/gobj-ui 7.23.54 → 7.23.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7515,10 +7515,41 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
7515
7515
  $extend.dataset.form_tag = tag;
7516
7516
  $extend.dataset.form_input_type = inputType;
7517
7517
  $extend.classList.add("yui-form-data-input");
7518
+ apply_readonly_to_control(readonly, tag, $extend);
7518
7519
  }
7519
7520
  return $element;
7520
7521
  }
7521
7522
  /******************************************************************
7523
+ * `readonly` is an attribute of a TEXT control and of nothing else.
7524
+ *
7525
+ * A `<select>` ignores it. So does a checkbox, and so does a radio:
7526
+ * the browser accepts the attribute, stores it, and lets the reader
7527
+ * change the value anyway. Only `disabled` stops them, and tom-select
7528
+ * is a widget of its own that has to be told through its API.
7529
+ *
7530
+ * Which is why a col that is not `writable` used to render an
7531
+ * EDITABLE select: the field was built read-only, correctly, and the
7532
+ * three controls that cannot be read-only said nothing about it.
7533
+ *
7534
+ * `disabled` is safe here: the record is collected by reading each
7535
+ * marked control's value, never by submitting the form, so a disabled
7536
+ * control is still read -- unlike in a native submit, where it would
7537
+ * be dropped.
7538
+ ******************************************************************/
7539
+ function apply_readonly_to_control(readonly, tag, $extend) {
7540
+ if (!readonly) return;
7541
+ switch (tag) {
7542
+ case "select":
7543
+ case "checkbox":
7544
+ case "radio":
7545
+ $extend.setAttribute("disabled", "disabled");
7546
+ break;
7547
+ case "select2":
7548
+ $extend.setAttribute("disabled", "disabled");
7549
+ if ($extend.tom_select) $extend.tom_select.disable();
7550
+ }
7551
+ }
7552
+ /******************************************************************
7522
7553
  * Create coordinates
7523
7554
  ******************************************************************/
7524
7555
  function create_coordinates(gobj, attrs) {
@@ -7510,10 +7510,41 @@ function create_form_field(gobj, $form, prefix, field_desc, { tag, inputType, na
7510
7510
  $extend.dataset.form_tag = tag;
7511
7511
  $extend.dataset.form_input_type = inputType;
7512
7512
  $extend.classList.add("yui-form-data-input");
7513
+ apply_readonly_to_control(readonly, tag, $extend);
7513
7514
  }
7514
7515
  return $element;
7515
7516
  }
7516
7517
  /******************************************************************
7518
+ * `readonly` is an attribute of a TEXT control and of nothing else.
7519
+ *
7520
+ * A `<select>` ignores it. So does a checkbox, and so does a radio:
7521
+ * the browser accepts the attribute, stores it, and lets the reader
7522
+ * change the value anyway. Only `disabled` stops them, and tom-select
7523
+ * is a widget of its own that has to be told through its API.
7524
+ *
7525
+ * Which is why a col that is not `writable` used to render an
7526
+ * EDITABLE select: the field was built read-only, correctly, and the
7527
+ * three controls that cannot be read-only said nothing about it.
7528
+ *
7529
+ * `disabled` is safe here: the record is collected by reading each
7530
+ * marked control's value, never by submitting the form, so a disabled
7531
+ * control is still read -- unlike in a native submit, where it would
7532
+ * be dropped.
7533
+ ******************************************************************/
7534
+ function apply_readonly_to_control(readonly, tag, $extend) {
7535
+ if (!readonly) return;
7536
+ switch (tag) {
7537
+ case "select":
7538
+ case "checkbox":
7539
+ case "radio":
7540
+ $extend.setAttribute("disabled", "disabled");
7541
+ break;
7542
+ case "select2":
7543
+ $extend.setAttribute("disabled", "disabled");
7544
+ if ($extend.tom_select) $extend.tom_select.disable();
7545
+ }
7546
+ }
7547
+ /******************************************************************
7517
7548
  * Create coordinates
7518
7549
  ******************************************************************/
7519
7550
  function create_coordinates(gobj, attrs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.23.54",
3
+ "version": "7.23.55",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
package/src/c_yui_form.js CHANGED
@@ -1449,11 +1449,55 @@ function create_form_field(
1449
1449
  $extend.dataset.form_tag = tag;
1450
1450
  $extend.dataset.form_input_type = inputType;
1451
1451
  $extend.classList.add('yui-form-data-input');
1452
+
1453
+ apply_readonly_to_control(readonly, tag, $extend);
1452
1454
  }
1453
1455
 
1454
1456
  return $element;
1455
1457
  }
1456
1458
 
1459
+ /******************************************************************
1460
+ * `readonly` is an attribute of a TEXT control and of nothing else.
1461
+ *
1462
+ * A `<select>` ignores it. So does a checkbox, and so does a radio:
1463
+ * the browser accepts the attribute, stores it, and lets the reader
1464
+ * change the value anyway. Only `disabled` stops them, and tom-select
1465
+ * is a widget of its own that has to be told through its API.
1466
+ *
1467
+ * Which is why a col that is not `writable` used to render an
1468
+ * EDITABLE select: the field was built read-only, correctly, and the
1469
+ * three controls that cannot be read-only said nothing about it.
1470
+ *
1471
+ * `disabled` is safe here: the record is collected by reading each
1472
+ * marked control's value, never by submitting the form, so a disabled
1473
+ * control is still read -- unlike in a native submit, where it would
1474
+ * be dropped.
1475
+ ******************************************************************/
1476
+ function apply_readonly_to_control(readonly, tag, $extend)
1477
+ {
1478
+ if(!readonly) {
1479
+ return;
1480
+ }
1481
+
1482
+ switch(tag) {
1483
+ case 'select':
1484
+ case 'checkbox':
1485
+ case 'radio':
1486
+ $extend.setAttribute("disabled", "disabled");
1487
+ break;
1488
+ case 'select2':
1489
+ $extend.setAttribute("disabled", "disabled");
1490
+ if($extend.tom_select) {
1491
+ $extend.tom_select.disable();
1492
+ }
1493
+ break;
1494
+ default:
1495
+ /* A text control already carries `readonly`, which is the
1496
+ * better of the two: it stays selectable and copyable. */
1497
+ break;
1498
+ }
1499
+ }
1500
+
1457
1501
 
1458
1502
  /******************************************************************
1459
1503
  * Create coordinates