-
Notifications
You must be signed in to change notification settings - Fork 34
Add country form to React #1360
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,89 @@ | ||||||||||||
class AddCountryForm extends React.Component { | ||||||||||||
|
||||||||||||
constructor(props) { | ||||||||||||
super(props); | ||||||||||||
this.state = { | ||||||||||||
nameInEnglish: "", | ||||||||||||
nameInRussian: "" | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, prefer single quotes over double one. |
||||||||||||
}; | ||||||||||||
this.handleSubmit = this.handleSubmit.bind(this); | ||||||||||||
this.handleChange = this.handleChange.bind(this); | ||||||||||||
} | ||||||||||||
|
||||||||||||
handleChange(event) { | ||||||||||||
event.preventDefault(); | ||||||||||||
this.setState({ | ||||||||||||
[event.target.name]: event.target.value | ||||||||||||
}); | ||||||||||||
} | ||||||||||||
|
||||||||||||
handleSubmit(event) { | ||||||||||||
event.preventDefault(); | ||||||||||||
|
||||||||||||
this.setState({}); | ||||||||||||
|
||||||||||||
axios.post( | ||||||||||||
"categories",{},{} | ||||||||||||
).then(response => { | ||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you plan to implement this logic? |
||||||||||||
}).catch(error => { | ||||||||||||
|
||||||||||||
}); | ||||||||||||
|
||||||||||||
} | ||||||||||||
|
||||||||||||
render() { | ||||||||||||
return ( | ||||||||||||
<form id="add-country-form" className="form-horizontal" onSubmit={this.handleSubmit} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add
|
||||||||||||
/* method="post" action="info.html" th:action="@{${ADD_COUNTRY_PAGE}}" th:object="${addCountryForm}" */> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line can be removed. |
||||||||||||
|
||||||||||||
<div className="form-group" /* th:classappend="${#fields.hasErrors('name') ? 'has-error' : ''}" */> | ||||||||||||
<label htmlFor="name" className="control-label col-sm-4"> | ||||||||||||
<span /* th:remove="tag" th:text="#{t_name_in_english}" */> | ||||||||||||
Name (in English) | ||||||||||||
</span> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The <label htmlFor="name" className="control-label col-sm-4">
{ this.props.l10n['t_name_in_english'] || 'Name (in English)' }
<span className="required_field">*</span>
</label> |
||||||||||||
<span className="required_field">*</span> | ||||||||||||
</label> | ||||||||||||
<div className="col-sm-5"> | ||||||||||||
<input id="name" | ||||||||||||
type="text" | ||||||||||||
className="form-control" | ||||||||||||
value={this.state.nameInEnglish} | ||||||||||||
name="nameInEnglish" | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this "name" attribute is needed for |
||||||||||||
required="required" | ||||||||||||
onChange={this.handleChange} /* th:field="*{name}" */ /> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
{/* | ||||||||||||
<span id="name.errors" class="help-block" th:if="${#fields.hasErrors('name')}" th:each="error : ${#fields.errors('name')}" th:text="${error}"></span> | ||||||||||||
*/} | ||||||||||||
</div> | ||||||||||||
</div> | ||||||||||||
|
||||||||||||
<div className="form-group" /* th:classappend="${#fields.hasErrors('nameRu') ? 'has-error' : ''}" */> | ||||||||||||
<label htmlFor="nameRu" className="control-label col-sm-4" /* th:text="#{t_name_in_russian}" */> | ||||||||||||
Name (in Russian) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Localization should be supported. |
||||||||||||
</label> | ||||||||||||
<div className="col-sm-5"> | ||||||||||||
<input id="nameRu" | ||||||||||||
type="text" | ||||||||||||
className="form-control" | ||||||||||||
value={this.state.nameInRussian} | ||||||||||||
name="nameInRussian" | ||||||||||||
onChange={this.handleChange} /* th:field="*{nameRu}" */ /> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
{/* | ||||||||||||
<span id="nameRu.errors" class="help-block" th:if="${#fields.hasErrors('nameRu')}" th:each="error : ${#fields.errors('nameRu')}" th:text="${error}"></span> | ||||||||||||
*/} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be implemented like there: mystamps/src/main/frontend/src/components/SimilarSeriesForm.js Lines 111 to 113 in 778dc2a
|
||||||||||||
</div> | ||||||||||||
</div> | ||||||||||||
|
||||||||||||
<div className="form-group"> | ||||||||||||
<div className="col-sm-offset-4 col-sm-5"> | ||||||||||||
<input type="submit" | ||||||||||||
className="btn btn-primary" | ||||||||||||
value="Add" /* th:value="#{t_add}" */ /> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add localization and convert it into a button. Like there: mystamps/src/main/frontend/src/components/SimilarSeriesForm.js Lines 105 to 109 in 778dc2a
|
||||||||||||
</div> | ||||||||||||
</div> | ||||||||||||
|
||||||||||||
</form> | ||||||||||||
) | ||||||||||||
} | ||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,43 +73,8 @@ <h3 th:text="${#strings.capitalize(add_country)}"> | |
</small> | ||
</div> | ||
|
||
<form id="add-country-form" method="post" class="form-horizontal" action="info.html" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't remove the form in this PR. Everything should continue to work until we fully re-implement existing logic. Can we try to render the component into id="add-country-form" or we need a separate element for that? |
||
th:action="@{${ADD_COUNTRY_PAGE}}" th:object="${addCountryForm}"> | ||
|
||
<div class="form-group" th:classappend="${#fields.hasErrors('name') ? 'has-error' : ''}"> | ||
<label for="name" class="control-label col-sm-4"> | ||
<span th:remove="tag" th:text="#{t_name_in_english}"> | ||
Name (in English) | ||
</span> | ||
<span class="required_field">*</span> | ||
</label> | ||
<div class="col-sm-5"> | ||
<input id="name" type="text" class="form-control" required="required" th:field="*{name}" /> | ||
<!--/*/ | ||
<span id="name.errors" class="help-block" th:if="${#fields.hasErrors('name')}" th:each="error : ${#fields.errors('name')}" th:text="${error}"></span> | ||
/*/--> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group" th:classappend="${#fields.hasErrors('nameRu') ? 'has-error' : ''}"> | ||
<label for="nameRu" class="control-label col-sm-4" th:text="#{t_name_in_russian}"> | ||
Name (in Russian) | ||
</label> | ||
<div class="col-sm-5"> | ||
<input id="nameRu" type="text" class="form-control" th:field="*{nameRu}" /> | ||
<!--/*/ | ||
<span id="nameRu.errors" class="help-block" th:if="${#fields.hasErrors('nameRu')}" th:each="error : ${#fields.errors('nameRu')}" th:text="${error}"></span> | ||
/*/--> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-sm-offset-4 col-sm-5"> | ||
<input type="submit" class="btn btn-primary" value="Add" th:value="#{t_add}" /> | ||
</div> | ||
</div> | ||
|
||
</form> | ||
<div id="add-country-form-react"></div> | ||
|
||
</div> | ||
</div> | ||
<div class="row"> | ||
|
@@ -123,5 +88,14 @@ <h3 th:text="${#strings.capitalize(add_country)}"> | |
<!-- Placed at the end of the document so the pages load faster --> | ||
<script src="http://yandex.st/jquery/1.9.1/jquery.min.js" th:src="${JQUERY_JS}"></script> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" th:src="${BOOTSTRAP_JS}"></script> | ||
|
||
<script src="https://unpkg.com/[email protected]/umd/react.development.js" th:src="${REACT_JS}"></script> | ||
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js" th:src="${REACT_DOM_JS}"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/axios.js" th:src="${AXIOS_JS}"></script> | ||
|
||
<script src="../../../../../../target/classes/js/components/AddCountryForm.js"></script> | ||
<script th:inline="javascript"> | ||
ReactDOM.render(React.createElement(AddCountryForm), document.getElementById('add-country-form-react')); | ||
</script> | ||
</body> | ||
</html> |
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.
Could you prepend a comment like this?
mystamps/src/main/frontend/src/components/SeriesSaleImportForm.js
Lines 1 to 5 in 778dc2a