@goldenpine/react-form-builder2 0.20.3-build.28 → 0.20.3-build.29

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.
@@ -37,6 +37,7 @@ var CustomElement = /*#__PURE__*/function (_Component) {
37
37
  var props = {};
38
38
  props.name = this.props.data.field_name;
39
39
  props.defaultValue = this.props.defaultValue;
40
+ var labelHidden = this.props.data.labelHidden || false;
40
41
  if (this.props.mutable && this.props.data.forwardRef) {
41
42
  props.ref = this.inputField;
42
43
  }
@@ -58,9 +59,9 @@ var CustomElement = /*#__PURE__*/function (_Component) {
58
59
  data: this.props.data
59
60
  }, this.props.data.props, props)) : /*#__PURE__*/_react["default"].createElement("div", {
60
61
  className: "mb-3"
61
- }, /*#__PURE__*/_react["default"].createElement(_componentLabel["default"], (0, _extends2["default"])({
62
- className: "form-label"
63
- }, this.props)), /*#__PURE__*/_react["default"].createElement(Element, (0, _extends2["default"])({
62
+ }, /*#__PURE__*/_react["default"].createElement(_componentLabel["default"], (0, _extends2["default"])({}, this.props, {
63
+ className: ["form-label", this.props.className, labelHidden ? "d-none" : ""].filter(Boolean).join(" ")
64
+ })), /*#__PURE__*/_react["default"].createElement(Element, (0, _extends2["default"])({
64
65
  data: this.props.data
65
66
  }, this.props.data.props, props))));
66
67
  }
@@ -30,6 +30,17 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
30
30
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
31
31
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /* eslint-disable quote-props */ // eslint-disable-next-line max-classes-per-file
32
32
  var FormElements = {};
33
+
34
+ // Helper function to format placeholder with asterisk if the field is required and label is hidden.
35
+ // The function checks if the field has a required label, if the label is hidden, and if the placeholder is not empty.
36
+ // If all conditions are met, it appends an asterisk to the placeholder.
37
+ function formatPlaceholder(placeholder, hasRequiredLabel, labelHidden) {
38
+ var result = placeholder || '';
39
+ if (hasRequiredLabel && labelHidden && result.trim() !== '' && !result.endsWith('*')) {
40
+ result += ' *';
41
+ }
42
+ return result;
43
+ }
33
44
  var Header = /*#__PURE__*/function (_React$Component) {
34
45
  function Header() {
35
46
  (0, _classCallCheck2["default"])(this, Header);
@@ -163,8 +174,9 @@ var TextInput = /*#__PURE__*/function (_React$Component5) {
163
174
  props.type = 'text';
164
175
  props.className = 'form-control';
165
176
  props.name = this.props.data.field_name;
166
- props.placeholder = this.props.data.placeholder || '';
167
177
  var labelHidden = this.props.data.labelHidden || false;
178
+ var hasRequiredLabel = this.props.data.hasOwnProperty('required') && this.props.data.required === true && !this.props.read_only;
179
+ props.placeholder = formatPlaceholder(this.props.data.placeholder, hasRequiredLabel, labelHidden);
168
180
  if (this.props.mutable) {
169
181
  props.defaultValue = this.props.defaultValue;
170
182
  props.ref = this.inputField;
@@ -205,8 +217,9 @@ var EmailInput = /*#__PURE__*/function (_React$Component6) {
205
217
  props.type = 'text';
206
218
  props.className = 'form-control';
207
219
  props.name = this.props.data.field_name;
208
- props.placeholder = this.props.data.placeholder || '';
209
220
  var labelHidden = this.props.data.labelHidden || false;
221
+ var hasRequiredLabel = this.props.data.hasOwnProperty('required') && this.props.data.required === true && !this.props.read_only;
222
+ props.placeholder = formatPlaceholder(this.props.data.placeholder, hasRequiredLabel, labelHidden);
210
223
  if (this.props.mutable) {
211
224
  props.defaultValue = this.props.defaultValue;
212
225
  props.ref = this.inputField;
@@ -245,12 +258,15 @@ var PhoneNumber = /*#__PURE__*/function (_React$Component7) {
245
258
  props.type = 'tel';
246
259
  props.className = 'form-control';
247
260
  props.name = this.props.data.field_name;
261
+ var labelHidden = this.props.data.labelHidden || false;
262
+ var hasRequiredLabel = this.props.data.hasOwnProperty('required') && this.props.data.required === true && !this.props.read_only;
263
+ var placeholder; // For phone number input, if placeholder is not set, we will set a default placeholder with an asterisk if it's required, to give users a hint about the expected format and the requirement. The default placeholder is "+12345678900" which is in E.164 format without spaces or dashes, as it's the most widely accepted format for international phone numbers and works well with the pattern validation we have in place. Merchants can customize this placeholder or even disable it by leaving it blank in the form builder.
248
264
  if (this.props.data.placeholder !== undefined && this.props.data.placeholder !== null) {
249
- props.placeholder = this.props.data.placeholder;
265
+ placeholder = this.props.data.placeholder;
250
266
  } else {
251
- props.placeholder = '+12345678900';
267
+ placeholder = '+12345678900';
252
268
  }
253
- var labelHidden = this.props.data.labelHidden || false;
269
+ props.placeholder = formatPlaceholder(placeholder, hasRequiredLabel, labelHidden);
254
270
  if (this.props.mutable) {
255
271
  props.defaultValue = this.props.defaultValue;
256
272
  props.ref = this.inputField;
@@ -289,8 +305,9 @@ var NumberInput = /*#__PURE__*/function (_React$Component8) {
289
305
  props.type = 'number';
290
306
  props.className = 'form-control';
291
307
  props.name = this.props.data.field_name;
292
- props.placeholder = this.props.data.placeholder || '';
293
308
  var labelHidden = this.props.data.labelHidden || false;
309
+ var hasRequiredLabel = this.props.data.hasOwnProperty('required') && this.props.data.required === true && !this.props.read_only;
310
+ props.placeholder = formatPlaceholder(this.props.data.placeholder, hasRequiredLabel, labelHidden);
294
311
  if (this.props.mutable) {
295
312
  props.defaultValue = this.props.defaultValue;
296
313
  props.ref = this.inputField;
@@ -328,8 +345,9 @@ var TextArea = /*#__PURE__*/function (_React$Component9) {
328
345
  var props = {};
329
346
  props.className = 'form-control';
330
347
  props.name = this.props.data.field_name;
331
- props.placeholder = this.props.data.placeholder || '';
332
348
  var labelHidden = this.props.data.labelHidden || false;
349
+ var hasRequiredLabel = this.props.data.hasOwnProperty('required') && this.props.data.required === true && !this.props.read_only;
350
+ props.placeholder = formatPlaceholder(this.props.data.placeholder, hasRequiredLabel, labelHidden);
333
351
  if (this.props.read_only) {
334
352
  props.disabled = 'disabled';
335
353
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goldenpine/react-form-builder2",
3
- "version": "0.20.3-build.28",
3
+ "version": "0.20.3-build.29",
4
4
  "description": "A complete form builder for react.",
5
5
  "main": "lib/index.js",
6
6
  "types": "types/index.d.ts",