Added data mutator to form processing. This allows conversion of data between server and a component (TreeTable in our case).

This commit is contained in:
Tomas Bures 2017-06-06 00:24:39 +02:00
parent 5e4c86f626
commit 61893d77f6
2 changed files with 37 additions and 15 deletions

View file

@ -18,7 +18,9 @@ export default class Edit extends Component {
console.log('Constructing Edit');
this.initFormState();
this.populateFormValuesFromURL(`/namespaces/rest/namespaces/${this.nsId}`);
this.getFormValuesFromURL(`/namespaces/rest/namespaces/${this.nsId}`, data => {
if (data.parent) data.parent = data.parent.toString();
});
}
validateFormValues(state) {
@ -32,14 +34,15 @@ export default class Edit extends Component {
}
async submitHandler() {
if (this.isFormWithoutErrors()) {
const data = this.getFormValues();
console.log(data);
const t = this.props.t;
await axios.put(`/namespaces/rest/namespaces/${this.nsId}`, data);
} else {
this.showFormValidation();
}
await this.validateAndPutFormValuesToURL(`/namespaces/rest/namespaces/${this.nsId}`, data => {
if (data.parent) data.parent = parseInt(data.parent);
});
this.navigateToWithFlashMessage('/namespaces', 'success', t('Namespace saved'));
// FIXME - the enable form in form.js gets called. This causes a warning. Check there whether the component is still mounted.
}
async deleteHandler() {