I have some issues configuring a button in my app.
I have a "Save button" that needs to check for conditions before allowing the user to save.
I have tried different codes, but the issue seems to be that it is not able to read in real-time whether the user has indeed met the conditions when trying to save. For example, if the user has chosen a certain value in a dropdown (like "Standard"), the message "Please write a justification..." still appears. The same issue happens for all the fields the user is supposed to fill out. I have also tried different options, such as checking the length of strings, using different functions like IsEmpty
, IsBlank
, and =Blank()
.
I have also tried different structures in the code (see two examples below):
Example 1
// Initialize a flag to track validation status
Set(isValid; true);
// Check if Dropdown is selected (cannot be empty)
If(
IsBlank(Dropdown.Selected.Value) Or Dropdown.Selected.Value = "";
Notify("Please select an option before saving"; NotificationType.Error);
Set(isValid; false) // Set flag to false if condition fails
);
// Check if Dropdown is a specific value and TextInput is blank
If(
(Dropdown.Selected.Value = "SpecificValue" Or Dropdown.Selected.Value = "AnotherValue") And IsBlank(TextInput.Text);
Notify("For selected options, please write a justification in the comment section before saving"; NotificationType.Error);
Set(isValid; false) // Set flag to false if condition fails
);
// Check if at least one other field is selected
If(
IsBlank(Dropdown1.Selected.Value) And
IsBlank(Dropdown2.Selected.Value);
Notify("Please select at least one option before saving"; NotificationType.Error);
Set(isValid; false) // Set flag to false if condition fails
);
// Now that we've validated, check if the flag is still true
If(
isValid;
Patch(
DataSource;
LookUp(DataSource; ID = CustomerID.Text);
{
Dropdown: Dropdown.Selected.Value;
Dropdown1: Dropdown1.Selected.Value;
Dropdown2: Dropdown2.Selected.Value;
TextInput: TextInput.Text;
Field2: Field2.Text;
Timestamp: Timestamp.Text
}
);
Notify("Data successfully saved"; NotificationType.Success);
// Reset fields after submission
Reset(CustomerID);
Reset(Dropdown);
Reset(Dropdown1);
Reset(Dropdown2);
Reset(TextInput);
Reset(Field2) // Reset additional fields
)
Example 2
If(
// Check if Dropdown is empty (no value selected)
IsBlank(Dropdown.Selected.Value) Or Dropdown.Selected.Value = "";
Notify("Please select an option before saving"; NotificationType.Error);
false; // Stop execution if Dropdown is not selected
// Check if Dropdown is specific value and TextInput is blank
(Dropdown.Selected.Value = "SpecificValue" Or Dropdown.Selected.Value = "AnotherValue") And IsBlank(TextInput.Text);
Notify("For specific options, please write a justification in the comment section before saving"; NotificationType.Error);
false; // Stop execution if TextInput is empty for specific options
// Check if no other fields are selected (all Dropdowns are empty)
IsBlank(Dropdown1.Selected.Value) And
IsBlank(Dropdown2.Selected.Value);
Notify("Please select at least one option before saving"; NotificationType.Error);
false; // Stop execution if no Dropdown is selected
// Check if Field2 text field is empty
IsBlank(Field2.Text);
Notify("Please provide the 'Field2' field before saving"; NotificationType.Error);
false; // Stop execution if Field2 is empty
// If all conditions pass, return true to execute Patch
true
);
// Only run Patch if all validations pass
If(
true; // Proceed if all conditions are met
Patch(
DataSource;
LookUp(DataSource; ID = CustomerID.Text);
{
Dropdown: Dropdown.Selected.Value;
Dropdown1: Dropdown1.Selected.Value;
Dropdown2: Dropdown2.Selected.Value;
TextInput: TextInput.Text;
Field2: Field2.Text; // Updated to reflect correct field name
Timestamp: Timestamp.Text
}
);
// Notify success after Patch operation
Notify("Data successfully saved"; NotificationType.Success);
// Reset fields after submission
Reset(CustomerID);
Reset(Dropdown);
Reset(Dropdown1);
Reset(Dropdown2);
Reset(TextInput);
Reset(Field2); // Reset Field2 field
)