Skip to content

Commit 218cddf

Browse files
authored
Fix(content-restriction): show field options in URM Form Field condition rules and center add/remove icons [UR-4514] (#1345)
1 parent f2019f2 commit 218cddf

5 files changed

Lines changed: 89 additions & 11 deletions

File tree

assets/css/urcr-shared.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,28 @@ $border-color_6: #475bb2;
309309
}
310310

311311
.button {
312+
display: inline-flex !important;
313+
align-items: center;
314+
justify-content: center;
312315
width: 28px !important;
313316
min-width: 28px !important;
314317
min-height: 26px !important;
315318
background: #eeeeee !important;
316319

320+
.dashicons {
321+
display: flex !important;
322+
align-items: center;
323+
justify-content: center;
324+
width: 20px !important;
325+
height: 20px !important;
326+
line-height: 20px !important;
327+
328+
&::before {
329+
font-size: 18px !important;
330+
line-height: 20px !important;
331+
}
332+
}
333+
317334
&.urcr-remove-field-button {
318335
margin-left: 0;
319336

modules/content-restriction/admin/class-urcr-admin-assets.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ public static function get_localized_data() {
137137
if( !empty($data['field_key']) && "membership" === $data['field_key'] ) {
138138
continue;
139139
}
140-
$form_fields[ $field_name ] = $data['label'];
140+
$form_fields[ $field_name ] = array(
141+
'label' => isset( $data['label'] ) ? $data['label'] : $field_name,
142+
'type' => isset( $data['type'] ) ? $data['type'] : '',
143+
'options' => isset( $data['options'] ) ? $data['options'] : array(),
144+
);
141145
}
142146
$ur_forms[ $form_id ] = $form_fields;
143147
}

src/content-restriction/components/inputs/ConditionValueInput.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ const ConditionValueInput = ({ type, field, value, operator, onChange, uniqueId,
184184
// Add form fields from ur_form_data
185185
Object.entries(urFormData).forEach(([formId, formFields]) => {
186186
if (formFields && typeof formFields === 'object') {
187-
Object.entries(formFields).forEach(([fieldName, fieldLabel]) => {
187+
Object.entries(formFields).forEach(([fieldName, fieldData]) => {
188+
const fieldLabel = fieldData && typeof fieldData === "object" ? fieldData.label : fieldData;
188189
formOptions.push({
189190
value: `${formId}:${fieldName}`,
190191
label: `${urForms[formId] || formId} - ${fieldLabel || fieldName}`,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React from "react";
2+
import { __ } from "@wordpress/i18n";
3+
4+
/**
5+
* Value widget for a single "URM Form Field" condition row.
6+
*
7+
* When the selected form field carries a fixed set of choices (select / radio /
8+
* checkbox / country, etc.), render a dropdown of those options. Otherwise fall
9+
* back to a free-text input. The value is always a single scalar string so it
10+
* matches the server-side `===` comparison in functions-urcr-core.php.
11+
*
12+
* @param {Object} props.fieldMeta Field meta from ur_form_data, e.g. { label, type, options }.
13+
* @param {string} props.value Current stored value.
14+
* @param {Function} props.onChange Called with the new scalar value.
15+
* @param {boolean} props.disabled Whether the control is disabled.
16+
* @param {Object} props.style Inline style forwarded to the control (width, etc.).
17+
*/
18+
const FormFieldValueInput = ({ fieldMeta, value, onChange, disabled = false, style = {} }) => {
19+
const options =
20+
fieldMeta && fieldMeta.options && typeof fieldMeta.options === "object"
21+
? fieldMeta.options
22+
: {};
23+
const optionEntries = Object.entries(options);
24+
25+
if (optionEntries.length > 0) {
26+
return (
27+
<select
28+
className="components-select-control__input urcr-condition-value-input urcr-condition-value-select"
29+
value={value || ""}
30+
onChange={(e) => onChange(e.target.value)}
31+
disabled={disabled}
32+
style={style}
33+
>
34+
<option value="">{__("Select value", "user-registration")}</option>
35+
{optionEntries.map(([optValue, optLabel]) => (
36+
<option key={optValue} value={optValue}>
37+
{optLabel || optValue}
38+
</option>
39+
))}
40+
</select>
41+
);
42+
}
43+
44+
return (
45+
<input
46+
type="text"
47+
className="components-text-control__input urcr-condition-value-input urcr-condition-value-text"
48+
value={value || ""}
49+
onChange={(e) => onChange(e.target.value)}
50+
placeholder={__("Enter value", "user-registration")}
51+
disabled={disabled}
52+
style={style}
53+
/>
54+
);
55+
};
56+
57+
export default FormFieldValueInput;

src/content-restriction/components/rules/URFormFieldCondition.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect, useRef } from "react";
22
import { __ } from "@wordpress/i18n";
33
import { getURCRData } from "../../utils/localized-data";
4+
import FormFieldValueInput from "../inputs/FormFieldValueInput";
45

56
const URFormFieldCondition = ({
67
condition,
@@ -94,9 +95,9 @@ const URFormFieldCondition = ({
9495
return [];
9596
}
9697
const fields = urFormData[formId];
97-
return Object.entries(fields).map(([fieldName, fieldLabel]) => ({
98+
return Object.entries(fields).map(([fieldName, fieldData]) => ({
9899
value: fieldName,
99-
label: fieldLabel || fieldName
100+
label: (fieldData && typeof fieldData === "object" ? fieldData.label : fieldData) || fieldName
100101
}));
101102
};
102103

@@ -199,14 +200,12 @@ const URFormFieldCondition = ({
199200

200201
{(field.operator !== "empty" && field.operator !== "not empty") && (
201202
<div className="urcr-form-field-value ur-flex-1" style={{ minWidth: 0 }}>
202-
<input
203-
type="text"
204-
className="components-text-control__input urcr-condition-value-input urcr-condition-value-text"
205-
value={field.value || ""}
206-
onChange={(e) => handleFieldUpdate(index, { value: e.target.value })}
207-
placeholder={__("Enter value", "user-registration")}
203+
<FormFieldValueInput
204+
fieldMeta={urFormData[formId] ? urFormData[formId][field.field_name] : null}
205+
value={field.value}
206+
onChange={(newValue) => handleFieldUpdate(index, { value: newValue })}
208207
disabled={disabled}
209-
style={{ width: "150px" }}
208+
style={{ width: "100%" }}
210209
/>
211210
</div>
212211
)}

0 commit comments

Comments
 (0)