mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Fix date components and new doc validation
This commit is contained in:
parent
ce7e0b0b25
commit
9aa06cee82
5 changed files with 45 additions and 43 deletions
|
@ -651,6 +651,7 @@ class Form extends Component {
|
|||
<Components.FormGroup
|
||||
key={group.name}
|
||||
{...group}
|
||||
errors={this.state.errors}
|
||||
currentValues={this.state.currentValues}
|
||||
updateCurrentValues={this.updateCurrentValues}
|
||||
formType={this.getFormType()}
|
||||
|
|
|
@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
|||
import DateTimePicker from 'react-datetime';
|
||||
import { registerComponent } from 'meteor/vulcan:core';
|
||||
|
||||
class Date extends PureComponent {
|
||||
class DateComponent extends PureComponent {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
@ -11,14 +11,14 @@ class Date extends PureComponent {
|
|||
}
|
||||
|
||||
// when the datetime picker has mounted, SmartForm will catch the date value (no formsy mixin in this component)
|
||||
componentDidMount() {
|
||||
if (this.props.value) {
|
||||
this.updateDate(this.props.value);
|
||||
}
|
||||
}
|
||||
// componentDidMount() {
|
||||
// if (this.props.value) {
|
||||
// this.updateDate(this.props.value);
|
||||
// }
|
||||
// }
|
||||
|
||||
updateDate(date) {
|
||||
this.context.updateCurrentValues({[this.props.name]: date});
|
||||
this.context.updateCurrentValues({[this.props.path]: date});
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -42,7 +42,7 @@ class Date extends PureComponent {
|
|||
}
|
||||
}
|
||||
|
||||
Date.propTypes = {
|
||||
DateComponent.propTypes = {
|
||||
control: PropTypes.any,
|
||||
datatype: PropTypes.any,
|
||||
group: PropTypes.any,
|
||||
|
@ -51,10 +51,10 @@ Date.propTypes = {
|
|||
value: PropTypes.any,
|
||||
};
|
||||
|
||||
Date.contextTypes = {
|
||||
DateComponent.contextTypes = {
|
||||
updateCurrentValues: PropTypes.func,
|
||||
};
|
||||
|
||||
export default Date;
|
||||
export default DateComponent;
|
||||
|
||||
registerComponent('FormComponentDate', Date);
|
||||
registerComponent('FormComponentDate', DateComponent);
|
|
@ -11,14 +11,14 @@ class DateTime extends PureComponent {
|
|||
}
|
||||
|
||||
// when the datetime picker has mounted, SmartForm will catch the date value (no formsy mixin in this component)
|
||||
componentDidMount() {
|
||||
if (this.props.value) {
|
||||
this.updateDate(this.props.value);
|
||||
}
|
||||
}
|
||||
// componentDidMount() {
|
||||
// if (this.props.value) {
|
||||
// this.updateDate(this.props.value);
|
||||
// }
|
||||
// }
|
||||
|
||||
updateDate(date) {
|
||||
this.context.updateCurrentValues({[this.props.name]: date});
|
||||
this.context.updateCurrentValues({[this.props.path]: date});
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -11,16 +11,16 @@ class Time extends PureComponent {
|
|||
}
|
||||
|
||||
// when the datetime picker has mounted, SmartForm will catch the date value (no formsy mixin in this component)
|
||||
componentDidMount() {
|
||||
if (this.props.value) {
|
||||
this.context.updateCurrentValues({[this.props.name]: this.props.value});
|
||||
}
|
||||
}
|
||||
// componentDidMount() {
|
||||
// if (this.props.value) {
|
||||
// this.context.updateCurrentValues({[this.props.path]: this.props.value});
|
||||
// }
|
||||
// }
|
||||
|
||||
updateDate(mDate) {
|
||||
// if this is a properly formatted moment date, update time
|
||||
if (typeof mDate === 'object') {
|
||||
this.context.updateCurrentValues({[this.props.name]: mDate.format('HH:mm')});
|
||||
this.context.updateCurrentValues({[this.props.path]: mDate.format('HH:mm')});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,26 +40,30 @@ export const validateDocument = (document, collection, context) => {
|
|||
});
|
||||
|
||||
// 4. check that required fields have a value
|
||||
_.keys(schema).forEach(fieldName => {
|
||||
const fieldSchema = schema[fieldName];
|
||||
// _.keys(schema).forEach(fieldName => {
|
||||
// const fieldSchema = schema[fieldName];
|
||||
|
||||
if ((fieldSchema.required || !fieldSchema.optional) && typeof document[fieldName] === 'undefined') {
|
||||
validationErrors.push({
|
||||
id: 'app.required_field_missing',
|
||||
data: { fieldName },
|
||||
});
|
||||
}
|
||||
});
|
||||
// if ((fieldSchema.required || !fieldSchema.optional) && typeof document[fieldName] === 'undefined') {
|
||||
// validationErrors.push({
|
||||
// id: 'app.required_field_missing',
|
||||
// data: { fieldName },
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
// 5. still run SS validation for now for backwards compatibility
|
||||
try {
|
||||
collection.simpleSchema().validate(document);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(error);
|
||||
validationErrors.push({
|
||||
id: 'app.schema_validation_error',
|
||||
data: { message: error.message },
|
||||
const validationContext = collection.simpleSchema().newContext();
|
||||
validationContext.validate(document);
|
||||
|
||||
if (!validationContext.isValid()) {
|
||||
const errors = validationContext.validationErrors();
|
||||
errors.forEach(error => {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log(error);
|
||||
validationErrors.push({
|
||||
id: 'app.schema_validation_error',
|
||||
data: error,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -133,9 +137,6 @@ export const validateModifier = (modifier, document, collection, context) => {
|
|||
|
||||
if (!validationContext.isValid()) {
|
||||
const errors = validationContext.validationErrors();
|
||||
console.log('// validationContext');
|
||||
console.log(validationContext.isValid());
|
||||
console.log(errors);
|
||||
errors.forEach(error => {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log(error);
|
||||
|
|
Loading…
Add table
Reference in a new issue