You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$500] PR 27825 RM - Save button should remain disabled until something is entered in the input field. #27998
Please re-state the problem that we are trying to solve in this issue.
Save button should be disabled until field is empty
What is the root cause of that problem?
Save button by default showing Active all the time, we need to disable the button
What changes do you think we should make in order to solve the problem?
We have to check input field is empty or not . we need to disable the save button by passing the value of input field as props from Form component to FormAlertWithSubmitButton component, using that value we need to write condition to disable or enable the button in FormAlertWithSubmitButton component
changed the title [-]PR 27825 RM - Save button should remain disabled until something is entered in the input field.[/-][+][$500] PR 27825 RM - Save button should remain disabled until something is entered in the input field.[/+]on Sep 25, 2023
Using hooks we can able to solve the issue easily in React js.
useState you have to use
const [state, updatedState] = useState(true);
If we create a button, it is enable by default. For disabling the button, we have to pass disabled={state}.
Based on your Query, we have to call a arrow function for the on-change function of input field, here event will trigger, when we enter something. So, here we have to write a if condition inside of the function was, if event has some length, only then updatedState should be set as false. Then the state value will hits to button disabled mode. Initially the state was set as true, but if we enter something in input field, then the event has some length, then the updatedState is setting as false in input field on-change function. So, based on your requirement, the save button, will only be enable, when we enter something on input field, until it will be disable mode only.
Hope you understand and the solution I have wrote will work definitely.
📣 @Mounika-Donga! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:
Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
With the implementation of React hooks, we can streamline the process of managing form inputs and button states. This solution is designed to resolve the issue seamlessly.
Here's a brief overview:
Use State Hook: We will use the useState hook to manage the state of the button. The initial state is set to true indicating that the button is disabled by default.
const[state,updateState]=useState(true);
Button State: The button's 'disabled' attribute will be controlled by the state. By default, it will be disabled.
<buttondisabled={state}>Submit</button>
Input Field & Event Handling: An arrow function will be called on the 'onChange' event of the input field. This event triggers whenever a user enters something into the field.
<inputtype="text"onChange={handleChange}/>
Inside this function, we'll include a conditional statement. If the input field has some content (i.e., its length is not zero), updateState will be set to false, enabling the button.
With this setup, the 'Submit' button will only be enabled when the input field contains some text. If the field is empty, the button will remain disabled.
I hope this explanation is clear. I'm confident that this solution will effectively address the issue at hand.
Please re-state the problem that we are trying to solve in this issue.
The issue at hand pertains to the absence of error handling for empty or whitespace-only waypoint values.
What is the root cause of that problem?
The root cause of this problem is the absence of whitespace validation when assessing the waypointValue during the validation process. This deficiency is observed in the code at line 107 of the WaypointEditor
What changes do you think we should make in order to solve the problem?
As specified in Forms.md, form submit buttons shall not be disabled. So disabling the button is out of the question.
I suggest we instead add || whiteSpaceRegex.test(waypointValue)as an additional condition in the if statement on line 107. This alteration will guarantee that an error is triggered when a user attempts to save an empty address.
const validate = (values) => {
const errors = {};
const whiteSpaceRegex = /^\s*$/;
const waypointValue = values[`waypoint${waypointIndex}`] || '';
if (isOffline && waypointValue !== '' && !ValidationUtils.isValidAddress(waypointValue)) {
ErrorUtils.addErrorMessage(errors, `waypoint${waypointIndex}`, 'bankAccount.error.address');
}
// If the user is online and they are trying to save a value without using the autocomplete, or are trying to save an empty address, show an error message instructing them to use a selected address instead.
// That enables us to save the address with coordinates when it is selected
if ((!isOffline && waypointValue !== '' && waypointAddress !== waypointValue) || whiteSpaceRegex.test(waypointValue)) {
ErrorUtils.addErrorMessage(errors, `waypoint${waypointIndex}`, 'distance.errors.selectSuggestedAddress');
}
return errors;
};
What alternative solutions did you explore? (Optional)
📣 @zmaqutu! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:
Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
I don't think the expected result is correct as we typically avoid disabling the submit button unless an API request is pending (see here).
I think we're possibly expecting an error, but only in the case of there being only a start and end point (i.e. no intermediate stops), see this comment on the original PR.
So in this video the behaviour is correct (no error), as we want to allow an empty address field as a way of deleting waypoints.
Screen.Recording.2023-08-16.at.11.26.34.AM.mov
cc @thienlnam since you worked on the original waypoints PR, do you know/remember if it's expected to have an error if no address is entered (whilst online) and the save button is pressed?
Activity
melvin-bot commentedon Sep 22, 2023
Triggered auto assignment to @greg-schroeder (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.melvin-bot commentedon Sep 22, 2023
Bug0 Triage Checklist (Main S/O)
Platformsin OP are ✅)izarutskaya commentedon Sep 22, 2023
Found when validating PR : #27825
DylanDylann commentedon Sep 22, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
Save button should remain disabled until something is entered in the input field
What is the root cause of that problem?
We don't have any validation in case the waypointValue is empty
App/src/pages/iou/WaypointEditor.js
Line 106 in 603dc58
What changes do you think we should make in order to solve the problem?
We can add validation like this
If we want to apply this validation only for start point and finish point we can add condition like this
Result
rajsixthblock commentedon Sep 22, 2023
### Proposal
Please re-state the problem that we are trying to solve in this issue.
Save button should be disabled until field is empty
What is the root cause of that problem?
Save button by default showing Active all the time, we need to disable the button
What changes do you think we should make in order to solve the problem?
We have to check input field is empty or not . we need to disable the save button by passing the value of input field as props from Form component to FormAlertWithSubmitButton component, using that value we need to write condition to disable or enable the button in FormAlertWithSubmitButton component
[-]PR 27825 RM - Save button should remain disabled until something is entered in the input field.[/-][+][$500] PR 27825 RM - Save button should remain disabled until something is entered in the input field.[/+]melvin-bot commentedon Sep 25, 2023
Job added to Upwork: https://www.upwork.com/jobs/~01153f7357f12f779a
melvin-bot commentedon Sep 25, 2023
Triggered auto assignment to @johncschuster (
External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.9 remaining items
Mounika-Donga commentedon Sep 25, 2023
Using hooks we can able to solve the issue easily in React js.
useState you have to use
const [state, updatedState] = useState(true);
If we create a button, it is enable by default. For disabling the button, we have to pass disabled={state}.
Based on your Query, we have to call a arrow function for the on-change function of input field, here event will trigger, when we enter something. So, here we have to write a if condition inside of the function was, if event has some length, only then updatedState should be set as false. Then the state value will hits to button disabled mode. Initially the state was set as true, but if we enter something in input field, then the event has some length, then the updatedState is setting as false in input field on-change function. So, based on your requirement, the save button, will only be enable, when we enter something on input field, until it will be disable mode only.
Hope you understand and the solution I have wrote will work definitely.
Thank You.......
melvin-bot commentedon Sep 25, 2023
📣 @Mounika-Donga! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:
Format:
carlitose commentedon Sep 25, 2023
With the implementation of React hooks, we can streamline the process of managing form inputs and button states. This solution is designed to resolve the issue seamlessly.
Here's a brief overview:
useStatehook to manage the state of the button. The initial state is set totrueindicating that the button is disabled by default.Inside this function, we'll include a conditional statement. If the input field has some content (i.e., its length is not zero),
updateStatewill be set tofalse, enabling the button.With this setup, the 'Submit' button will only be enabled when the input field contains some text. If the field is empty, the button will remain disabled.
I hope this explanation is clear. I'm confident that this solution will effectively address the issue at hand.
Thank you for considering this proposal.
Contributor details
Your Expensify account email: carlog.sergi@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~01b0d12422bbdbf2d3
melvin-bot commentedon Sep 25, 2023
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
zmaqutu commentedon Sep 25, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
The issue at hand pertains to the absence of error handling for empty or whitespace-only waypoint values.
What is the root cause of that problem?
The root cause of this problem is the absence of whitespace validation when assessing the waypointValue during the validation process. This deficiency is observed in the code at line 107 of the WaypointEditor
App/src/pages/iou/WaypointEditor.js
Lines 107 to 109 in 34e7377
What changes do you think we should make in order to solve the problem?
As specified in Forms.md, form submit buttons shall not be disabled. So disabling the button is out of the question.
I suggest we instead add
|| whiteSpaceRegex.test(waypointValue)as an additional condition in the if statement on line 107. This alteration will guarantee that an error is triggered when a user attempts to save an empty address.What alternative solutions did you explore? (Optional)
NA
melvin-bot commentedon Sep 25, 2023
📣 @zmaqutu! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:
Format:
zmaqutu commentedon Sep 25, 2023
Contributor details
Your Expensify account email: zmaqutu@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~01a04598e049270d15
melvin-bot commentedon Sep 25, 2023
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
johncschuster commentedon Sep 26, 2023
Looks like you've got this handled, @greg-schroeder. Unassigning myself!
zmaqutu commentedon Sep 26, 2023
Fix:
4824d7f07fb24f73a98c940172bc2b69.mp4
jjcoffee commentedon Sep 28, 2023
I don't think the expected result is correct as we typically avoid disabling the submit button unless an API request is pending (see here).
I think we're possibly expecting an error, but only in the case of there being only a start and end point (i.e. no intermediate stops), see this comment on the original PR.
So in this video the behaviour is correct (no error), as we want to allow an empty address field as a way of deleting waypoints.
Screen.Recording.2023-08-16.at.11.26.34.AM.mov
cc @thienlnam since you worked on the original waypoints PR, do you know/remember if it's expected to have an error if no address is entered (whilst online) and the save button is pressed?
DylanDylann commentedon Sep 28, 2023
updated proposal
thienlnam commentedon Sep 29, 2023
I'm closing this as it isn't a bug - you can save an empty waypoint to remove waypoints