-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: shift course form error handling to @edx/paragon styles #805
base: master
Are you sure you want to change the base?
Conversation
7513e46
to
fe90c5c
Compare
@@ -74,6 +74,10 @@ class DateTimeField extends React.Component { | |||
type, | |||
pattern, | |||
placeholder, | |||
meta: { | |||
touched, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is touched needed here? Why cant the decision be done with error variable alone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to prevent showing errors unnecessarily. Consider a form has just rendered with a required Datefield. Since the field is empty, the error prop will be true. However we do not wish to show it as an error, as the user has yet to interact with the field. To display errors properly, we need to keep track of whether the user has interacted with the field or not. For this we need the touched prop which will become active only if the user has touched the field e.g by clicking on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Is the prop coming from the react parent component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ummm yeah... we are rendering it inside redux-form so we don't pass the meta prop explicitly but redux-form automagically does that for us
src/utils/validation.js
Outdated
if (pattern.test(value)) { | ||
return undefined; | ||
} | ||
return 'Please Enter a valid course key'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: enter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/utils/validation.js
Outdated
} | ||
|
||
if (price < 1 || price > 1000) { | ||
return 'Price should be between 1 and 1000(endpoints inclusive)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space before (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/utils/validation.js
Outdated
const pattern = /^[0-9]+(\.)?[0-9]{0,2}$/; | ||
|
||
if (!pattern.test(value)) { | ||
return 'Please enter a valid price(with at most 2 decimal digits)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space before (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will let @AliAdnanSohail have a primary say on this since he had looked into this.
@@ -101,17 +106,28 @@ class BaseCreateCourseForm extends React.Component { | |||
<div className="create-course-form"> | |||
<h2>Create New Course</h2> | |||
<hr /> | |||
<form onSubmit={handleSubmit}> | |||
<form onSubmit={handleSubmit} noValidate> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is validation being removed when the form is submitted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this? Validation to the form is a must-have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well this is essentially the point of the PR....this removes the HTML(browser based) validation....if we don't do this then the browser will keep on showing its own tooltips on error fields....
we are doing the validations ourselves now...see the 'validate' prop passed to the Field
components
@@ -35,6 +35,13 @@ class CreateCoursePage extends React.Component { | |||
this.setStartedFetching(); | |||
} | |||
|
|||
componentDidUpdate(prevProps) { | |||
// check if errors on form submission and scroll to them | |||
if (this.props.courseInfo.error && (!prevProps.courseInfo || !prevProps.courseInfo.error)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is checking that previous props did not have course info and error but current props have errors, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
const handleCourseCreateFail = (errors) => { | ||
const fieldName = getFieldName(errors); | ||
if (fieldName) { | ||
const node = document.getElementsByName(fieldName)[0]; | ||
|
||
if (node) { node.scrollIntoView({ behavior: 'smooth' }); } | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this live in CourseCreateForm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handleCourseEditFail
also lives in the same file so I though it would be better to follow the precedent
@@ -101,17 +106,28 @@ class BaseCreateCourseForm extends React.Component { | |||
<div className="create-course-form"> | |||
<h2>Create New Course</h2> | |||
<hr /> | |||
<form onSubmit={handleSubmit}> | |||
<form onSubmit={handleSubmit} noValidate> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this? Validation to the form is a must-have.
@@ -188,6 +216,11 @@ class BaseCreateCourseForm extends React.Component { | |||
<Field | |||
name="courseRunKey" | |||
component={RenderInputTextField} | |||
props={ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed to make inline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -164,6 +171,14 @@ class CreateCoursePage extends React.Component { | |||
{ showForm | |||
&& ( | |||
<div> | |||
{errorArray.length > 1 && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would errorArray
contain if length is 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know...essentially this seems to be some sort of condition for displaying an error message....i have only changed the position of where the error message is being displayed....
if this ^ doesn't make sense, just look at the complete file and hopefully it will be clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just few nits to address
src/utils/validation.js
Outdated
if (pattern.test(value)) { | ||
return undefined; | ||
} | ||
return 'Enter a valid course key'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: To make it consistent with other error messages, update this to Please enter a valid course key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/components/PriceList/index.jsx
Outdated
@@ -17,6 +21,11 @@ const PriceList = ({ | |||
key={seatType} | |||
name={`prices.${seatType}`} | |||
component={RenderInputTextField} | |||
props={ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
props={ | |
props={{name: `prices.${seatType}`}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
6d1d2a0
to
ae6a40b
Compare
ae6a40b
to
a29ff37
Compare
PROD-2734
Description
This PR updates the Publisher create course form to incorporate edx/paragon based validation for form fields
Testing Instructions
New Course
.ScreenShots
Before
After
ToDo