Some small updates coming from IVIS

This commit is contained in:
Tomas Bures 2018-07-18 18:41:18 +01:00
parent 4943b22a51
commit e85c707973
14 changed files with 4319 additions and 2975 deletions

View file

@ -27,6 +27,7 @@ import styles from "./styles.scss";
import moment from "moment";
import {getUrl} from "./urls";
const FormState = {
Loading: 0,
LoadingWithNotice: 1,
@ -76,7 +77,7 @@ class Form extends Component {
const statusMessageText = owner.getFormStatusMessageText();
const statusMessageSeverity = owner.getFormStatusMessageSeverity();
let formClass = 'form-horizontal';
let formClass = `form-horizontal ${styles.form} `;
if (props.format === 'wide') {
formClass = '';
} else if (props.format === 'inline') {
@ -111,6 +112,7 @@ class Fieldset extends Component {
id: PropTypes.string,
label: PropTypes.string,
help: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
flat: PropTypes.bool
}
static contextTypes = {
@ -123,7 +125,7 @@ class Fieldset extends Component {
const id = this.props.id;
const htmlId = 'form_' + id;
const className = id ? owner.addFormValidationClass('', id) : '';
const className = id ? owner.addFormValidationClass('', id) : null;
let helpBlock = null;
if (this.props.help) {
@ -141,7 +143,7 @@ class Fieldset extends Component {
return (
<fieldset className={className}>
{props.label ? <legend>{props.label}</legend> : null}
<div className="fieldset-content">
<div className={props.flat ? 'fieldset-content fieldset-content-flat' : 'fieldset-content'}>
{props.children}
{helpBlock}
{validationBlock}
@ -1081,6 +1083,49 @@ function withForm(target) {
scheduleValidateForm(this);
};
inst.updateForm = function(mutator) {
this.setState(previousState => {
const onChangeBeforeValidationCallback = this.state.formSettings.onChangeBeforeValidation || {};
const formState = previousState.formState.withMutations(mutState => {
mutState.update('data', stateData => stateData.withMutations(mutStateData => {
mutator(mutStateData);
if (typeof onChangeBeforeValidationCallback === 'object') {
for (const key in onChangeBeforeValidationCallback) {
const oldValue = previousState.formState.getIn(['data', key, 'value']);
const newValue = mutStateData.getIn([key, 'value']);
onChangeBeforeValidationCallback[key](mutStateData, key, oldValue, newValue);
}
} else {
onChangeBeforeValidationCallback(mutStateData);
}
}));
validateFormState(this, mutState);
});
let newState = {
formState
};
const onChangeCallback = this.state.formSettings.onChange || {};
if (typeof onChangeCallback === 'object') {
for (const key in onChangeCallback) {
const oldValue = previousState.formState.getIn(['data', key, 'value']);
const newValue = formState.getIn(['data', key, 'value']);
onChangeCallback[key](newState, key, oldValue, newValue);
}
} else {
onChangeCallback(newState);
}
return newState;
});
};
inst.updateFormValue = function(key, value) {
this.setState(previousState => {
const oldValue = previousState.formState.getIn(['data', key, 'value']);