Skip to content

Commit

Permalink
post works with tags check
Browse files Browse the repository at this point in the history
  • Loading branch information
annyhe committed Nov 28, 2016
1 parent dca69c4 commit 3d5f345
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions view/admin/components/common/Forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const Form = React.createClass({
// what if needs more than name and value?
// unit test this
const propsFromForm = propertyMetaData[i].propsFromForm;
console.log(propsFromForm)
if (propsFromForm && propsFromForm.length) {
for (let j = propsFromForm.length - 1; j >= 0; j--) {
obj[propsFromForm[j]] = (
Expand All @@ -124,6 +125,7 @@ const Form = React.createClass({
let fieldValue = '';
// give value to custom renderer
if (propertyMetaData[i].hasOwnProperty('customOutput')) {
console.log('********', propertyMetaData[i].propertyName, obj)
// does every field have a fieldvalue?
fieldValue = propertyMetaData[i].customOutput(
Object.assign({}, obj, { disabled: !edit })
Expand Down
2 changes: 1 addition & 1 deletion view/admin/components/pages/Detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Detail extends React.Component {
const keys = Object.keys(failedFields);
if (keys.length) {
this.setIinvalidFieldObj(failedFields);
this.showError('error from create. ' + keys.join(', ') + ' failed validation');
this.showError('error from update: ' + keys.join(', ') + ' failed validation');
} else {
// all fields are valid
this.setIinvalidFieldObj({});
Expand Down
23 changes: 21 additions & 2 deletions view/admin/components/pages/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import ErrorRender from '../common/ErrorRender';
class List extends React.Component {
constructor(props) {
super(props);
this.setIinvalidFieldObj = this.setIinvalidFieldObj.bind(this);
this.postForm = this.postForm.bind(this);
this.showError = this.showError.bind(this);
this.closeError = this.closeError.bind(this);
Expand All @@ -42,6 +43,7 @@ class List extends React.Component {
this.state = {
delResource: false,
error: '',
invalidFieldObj: {},
};
}

Expand Down Expand Up @@ -84,16 +86,27 @@ class List extends React.Component {
const { history, postResource, checkValidation, url } = this.props;
// if array contains fields, show error
const failedFields = checkValidation(propertyMetaData, formObj);
if (failedFields.length) {
this.showError('error from create. ' + failedFields.join(', ') + ' failed validation');
const keys = Object.keys(failedFields);
if (keys.length) {
this.setIinvalidFieldObj(failedFields);
this.showError('error from create: ' + keys.join(', ') + ' failed validation');
} else {
// all fields valid
this.setIinvalidFieldObj({});
// go to details page
postResource(formObj, goToUrl, (redirectUrl) => {
history.push(redirectUrl);
});
}
}

// obj contains invalid fields and their data
setIinvalidFieldObj(invalidFieldObj) {
this.setState({
invalidFieldObj,
});
}

postForm() {
const { url, getFormData } = this.props;
const form = this.refs.addResourceForm;
Expand Down Expand Up @@ -152,6 +165,12 @@ class List extends React.Component {
tableOpts.parentAbsolutePath = urlQuery.split('=').pop() || 'dummy';
formOpts.parentAbsolutePath = urlQuery.split('=').pop();
}
const { invalidFieldObj } = this.state;
// if invalid input, show them
if ( Object.keys(invalidFieldObj).length) {
formOpts.data = invalidFieldObj;
}

const errorMessage = this.state.error ? <ErrorRender
hide={this.closeError.bind(this)}
error={ this.state.error }
Expand Down
1 change: 1 addition & 0 deletions view/admin/config/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ obj.samples = [
obj.subjects = [{
propertyName: 'name',
displayName: 'Name',
validate: /^[0-9A-Za-z_\\-]{1,60}$/,
}, {
propertyName: 'parentAbsolutePath',
displayName: 'Parent Absolute Path',
Expand Down
1 change: 1 addition & 0 deletions view/admin/config/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const subjectMetaData = [
{
propertyName: 'name',
displayName: 'Name',
validate: /^[0-9A-Za-z_\\-]{1,60}$/,
}, {
propertyName: 'parentAbsolutePath',
displayName: 'Parent Absolute Path',
Expand Down

0 comments on commit 3d5f345

Please sign in to comment.