Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track and handle hidden fields on publish forms to fix sometimes, required_if, etc. rules #5101

Merged
8 changes: 7 additions & 1 deletion resources/js/components/entries/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ export default {
return this.getPreference('after_save');
},

visibleValues() {
return _.omit(this.values, (_, handle) => {
return this.$store.state.publish.base.hiddenFields[handle];
jesseleite marked this conversation as resolved.
Show resolved Hide resolved
});
},

},

watch: {
Expand Down Expand Up @@ -464,7 +470,7 @@ export default {
performSaveRequest() {
// Once the hook has completed, we need to make the actual request.
// We build the payload here because the before hook may have modified values.
const payload = { ...this.values, ...{
const payload = { ...this.visibleValues, ...{
_blueprint: this.fieldset.handle,
_localized: this.localizedFields,
}};
Expand Down
9 changes: 7 additions & 2 deletions resources/js/components/field-conditions/ValidatorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ export default {

methods: {
showField(field) {
let validator = new Validator(field, this.values, this.$store, this.storeName);
let passes = new Validator(field, this.values, this.$store, this.storeName).passesConditions();

return validator.passesConditions();
Statamic.$store.commit(`publish/${this.storeName}/setHiddenField`, {
handle: field.handle,
hidden: ! passes,
});

return passes;
}
}
}
4 changes: 4 additions & 0 deletions resources/js/components/publish/Container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default {
state: {
blueprint: initial.blueprint,
values: initial.values,
hiddenFields: {},
meta: initial.meta,
localizedFields: initial.localizedFields,
site: initial.site,
Expand All @@ -112,6 +113,9 @@ export default {
setValues(state, values) {
state.values = values;
},
setHiddenField(state, field) {
state.hiddenFields[field.handle] = field.hidden;
},
setMeta(state, meta) {
state.meta = meta;
},
Expand Down