Validate JSON parameters
This change adds a global `isJson` validation rule to the App component
and uses it to validate parameter fields with the `json` type.
Change-Id: I7c6826a32af63fb862017ea53d710447b61e57b6
Closes-Bug: #1638523
(cherry picked from commit f7ddb65396
)
This commit is contained in:
parent
3634cdb420
commit
d5cd27997a
|
@ -26,6 +26,8 @@ export default class ParameterInput extends React.Component {
|
|||
title={label}
|
||||
description={description}
|
||||
value={defaultValue ? JSON.stringify(defaultValue.toJS()) : ''}
|
||||
validations="isJson"
|
||||
validationError="Please enter a valid JSON string"
|
||||
labelColumnClasses="col-sm-4"
|
||||
inputColumnClasses="col-sm-8"/>
|
||||
);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import Formsy from 'formsy-react';
|
||||
|
||||
/*
|
||||
* Custom validation rules used throughout the app.
|
||||
*/
|
||||
export default function initFormsy () {
|
||||
Formsy.addValidationRule('isJson', (values, value) => {
|
||||
try { return !!JSON.parse(value); }
|
||||
catch(e) { return false; }
|
||||
});
|
||||
}
|
|
@ -18,6 +18,7 @@ import EditPlan from './components/plan/EditPlan';
|
|||
import EnvironmentConfiguration from
|
||||
'./components/environment_configuration/EnvironmentConfiguration.js';
|
||||
import { getCurrentStackDeploymentInProgress } from './selectors/stacks';
|
||||
import initFormsy from './components/utils/Formsy';
|
||||
import ListPlans from './components/plan/ListPlans';
|
||||
import Login from './components/Login';
|
||||
import LoginActions from './actions/LoginActions';
|
||||
|
@ -129,6 +130,8 @@ TempStorage.initialized.then(() => {
|
|||
</Route>
|
||||
);
|
||||
|
||||
initFormsy();
|
||||
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
<IntlProvider locale="en">
|
||||
|
|
Loading…
Reference in New Issue