Allows validation onBlur and on submit in Item Edit Form.
This commit is contained in:
parent
dae37e9882
commit
5d618064ff
|
@ -213,12 +213,10 @@ export default {
|
|||
this.$router.push(this.$routerHelper.getItemPath(this.form.collectionId, this.itemId));
|
||||
})
|
||||
.catch((errors) => {
|
||||
this.$console.log(errors);
|
||||
for (let error of errors.errors) {
|
||||
for (let attribute of Object.keys(error)){
|
||||
//this.editFormErrors[attribute] = error[attribute];
|
||||
this.$console.log(error);
|
||||
|
||||
eventBus.errors.push({ field_id: 7031, errors: error[attribute]});
|
||||
for (let attribute of Object.keys(error)){
|
||||
eventBus.errors.push({ field_id: attribute, errors: error[attribute]});
|
||||
}
|
||||
}
|
||||
this.$console.log(eventBus.errors);
|
||||
|
|
|
@ -24,22 +24,22 @@
|
|||
</div>
|
||||
<div class="header-item">
|
||||
<b-field>
|
||||
<b-select
|
||||
@input="onChangeOrderBy($event)"
|
||||
:placeholder="$i18n.get('label_sorting')">
|
||||
<option
|
||||
v-for="(field, index) in tableFields"
|
||||
v-if="field.id != undefined"
|
||||
:value="field.id"
|
||||
:key="index">
|
||||
{{ field.label }}
|
||||
</option>
|
||||
</b-select>
|
||||
<button
|
||||
class="button is-small"
|
||||
@click="onChangeOrder()">
|
||||
<b-icon :icon="order == 'ASC' ? 'sort-ascending' : 'sort-descending'"/>
|
||||
</button>
|
||||
<b-select
|
||||
@input="onChangeOrderBy($event)"
|
||||
:placeholder="$i18n.get('label_sorting')">
|
||||
<option
|
||||
v-for="(field, index) in tableFields"
|
||||
v-if="field.id != undefined"
|
||||
:value="field"
|
||||
:key="index">
|
||||
{{ field.label }}
|
||||
</option>
|
||||
</b-select>
|
||||
<button
|
||||
class="button is-small"
|
||||
@click="onChangeOrder()">
|
||||
<b-icon :icon="order == 'ASC' ? 'sort-ascending' : 'sort-descending'"/>
|
||||
</button>
|
||||
</b-field>
|
||||
</div>
|
||||
</span>
|
||||
|
@ -51,11 +51,15 @@ import { eventSearchBus } from '../../../js/event-search-bus';
|
|||
|
||||
export default {
|
||||
name: 'SearchControl',
|
||||
data() {
|
||||
return {
|
||||
prefTableFields: []
|
||||
}
|
||||
},
|
||||
props: {
|
||||
collectionId: Number,
|
||||
isRepositoryLevel: false,
|
||||
tableFields: Array,
|
||||
prefTableFields: Array
|
||||
tableFields: Array
|
||||
},
|
||||
computed: {
|
||||
orderBy() {
|
||||
|
@ -66,9 +70,6 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions('fields', [
|
||||
'fetchFields'
|
||||
]),
|
||||
...mapGetters('search', [
|
||||
'getOrderBy',
|
||||
'getOrder'
|
||||
|
@ -88,33 +89,12 @@ export default {
|
|||
|
||||
// this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableFields, prevValue);
|
||||
},
|
||||
onChangeOrderBy(fieldId) {
|
||||
eventSearchBus.setOrderBy(fieldId);
|
||||
onChangeOrderBy(field) {
|
||||
eventSearchBus.setOrderBy(field);
|
||||
},
|
||||
onChangeOrder() {
|
||||
this.order == 'DESC' ? eventSearchBus.setOrder('ASC') : eventSearchBus.setOrder('DESC');
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then((res) => {
|
||||
let rawFields = res;
|
||||
this.tableFields.push({ label: this.$i18n.get('label_thumbnail'), field: 'featured_image', slug: 'featured_image', id: undefined, visible: true });
|
||||
for (let field of rawFields) {
|
||||
this.tableFields.push(
|
||||
{ label: field.name, field: field.description, slug: field.slug, id: field.id, visible: true }
|
||||
);
|
||||
}
|
||||
this.tableFields.push({ label: this.$i18n.get('label_actions'), field: 'row_actions', slug: 'actions', id: undefined, visible: true });
|
||||
this.prefTableFields = this.tableFields;
|
||||
// this.$userPrefs.get('table_columns_' + this.collectionId)
|
||||
// .then((value) => {
|
||||
// this.prefTableFields = value;
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableFields, null);
|
||||
// });
|
||||
|
||||
}).catch();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -68,6 +68,9 @@ export default {
|
|||
...mapGetters('collection', [
|
||||
'getItems'
|
||||
]),
|
||||
...mapActions('fields', [
|
||||
'fetchFields'
|
||||
]),
|
||||
},
|
||||
computed: {
|
||||
items(){
|
||||
|
@ -76,10 +79,31 @@ export default {
|
|||
},
|
||||
created() {
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
this.isRepositoryLevel = (this.collectionId == undefined);
|
||||
this.isRepositoryLevel = (this.collectionId == undefined);
|
||||
|
||||
eventSearchBus.$on('isLoadingItems', isLoadingItems => {
|
||||
this.isLoading = isLoadingItems;
|
||||
});
|
||||
|
||||
this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then((res) => {
|
||||
let rawFields = res;
|
||||
this.tableFields.push({ label: this.$i18n.get('label_thumbnail'), field: 'featured_image', field_type: undefined, slug: 'featured_image', id: undefined, visible: true });
|
||||
for (let field of rawFields) {
|
||||
this.tableFields.push(
|
||||
{ label: field.name, field: field.description, slug: field.slug, field_type: field.field_type, id: field.id, visible: true }
|
||||
);
|
||||
}
|
||||
this.tableFields.push({ label: this.$i18n.get('label_actions'), field: 'row_actions', field_type: undefined, slug: 'actions', id: undefined, visible: true });
|
||||
this.prefTableFields = this.tableFields;
|
||||
// this.$userPrefs.get('table_columns_' + this.collectionId)
|
||||
// .then((value) => {
|
||||
// this.prefTableFields = value;
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableFields, null);
|
||||
// });
|
||||
|
||||
}).catch();
|
||||
},
|
||||
mounted(){
|
||||
eventSearchBus.updateStoreFromURL();
|
||||
|
|
|
@ -154,6 +154,7 @@ html {
|
|||
|
||||
// Some components have a different style in listing pages
|
||||
.button {
|
||||
border: none;
|
||||
border-radius: 6px !important;
|
||||
font-weight: normal;
|
||||
padding: 2px 15px !important;
|
||||
|
|
|
@ -366,32 +366,25 @@ class Item extends Entity {
|
|||
return true;
|
||||
}
|
||||
|
||||
if ( parent::validate() ) {
|
||||
$arrayItemMetadata = $this->get_fields();
|
||||
if ( $arrayItemMetadata ) {
|
||||
foreach ( $arrayItemMetadata as $itemMetadata ) {
|
||||
$is_valid = true;
|
||||
|
||||
// avoid core fields to re-validate
|
||||
$pos = strpos( $itemMetadata->get_field()->get_field_type(), 'Core' );
|
||||
if ( $pos !== false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip validation for Compound Fields
|
||||
if ( $itemMetadata->get_field()->get_field_type() == 'Tainacan\Field_Types\Compound' ) {
|
||||
continue;
|
||||
}
|
||||
$arrayItemMetadata = $this->get_fields();
|
||||
if ( $arrayItemMetadata ) {
|
||||
foreach ( $arrayItemMetadata as $itemMetadata ) {
|
||||
|
||||
// skip validation for Compound Fields
|
||||
if ( $itemMetadata->get_field()->get_field_type() == 'Tainacan\Field_Types\Compound' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $itemMetadata->validate() ) {
|
||||
$errors = $itemMetadata->get_errors();
|
||||
$this->add_error( $itemMetadata->get_field()->get_id(), $errors );
|
||||
|
||||
return false;
|
||||
}
|
||||
if ( ! $itemMetadata->validate() ) {
|
||||
$errors = $itemMetadata->get_errors();
|
||||
$this->add_error( $itemMetadata->get_field()->get_id(), $errors );
|
||||
$is_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return $is_valid;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -71,12 +71,17 @@
|
|||
return this.inputs;
|
||||
},
|
||||
getErrorMessage() {
|
||||
|
||||
let msg = '';
|
||||
let errors = eventBus.getErrors(this.field.field.id);
|
||||
|
||||
if ( errors) {
|
||||
this.setFieldTypeMessage('is-danger');
|
||||
for (let index in errors) {
|
||||
msg += errors[index] + '\n';
|
||||
for (let error of errors) {
|
||||
for (let index of Object.keys(error)) {
|
||||
this.$console.log(index);
|
||||
msg += error[index] + '\n';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.setFieldTypeMessage('');
|
||||
|
|
|
@ -39,30 +39,31 @@ export const eventBus = new Vue({
|
|||
let values = ( Array.isArray( data.values[0] ) ) ? data.values[0] : data.values ;
|
||||
const promisse = this.$store.dispatch('item/updateMetadata',
|
||||
{ item_id: data.item_id, field_id: data.field_id, values: values });
|
||||
promisse.then( () => {
|
||||
let index = this.errors.findIndex( errorItem => errorItem.field_id === data.field_id );
|
||||
|
||||
promisse.then( () => {
|
||||
let index = this.errors.findIndex( errorItem => errorItem.field_id == data.field_id );
|
||||
if ( index >= 0){
|
||||
this.errors.splice( index, 1);
|
||||
}
|
||||
}, error => {
|
||||
let index = this.errors.findIndex( errorItem => errorItem.field_id === data.field_id );
|
||||
let messages = null;
|
||||
})
|
||||
.catch((error) => {
|
||||
let index = this.errors.findIndex( errorItem => errorItem.field_id == data.field_id );
|
||||
let messages = [];
|
||||
|
||||
for (let index in error) {
|
||||
messages = error[index]
|
||||
messages.push(error[index]);
|
||||
}
|
||||
|
||||
if ( index >= 0){
|
||||
Vue.set( this.errors, index, { field_id: data.field_id, errors: messages });
|
||||
}else{
|
||||
} else {
|
||||
this.errors.push( { field_id: data.field_id, errors: messages } );
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
getErrors(field_id){
|
||||
let error = this.errors.find( errorItem => errorItem.field_id === field_id );
|
||||
console.log(this.errors);
|
||||
let error = this.errors.find( errorItem => errorItem.field_id == field_id );
|
||||
return ( error ) ? error.errors : false
|
||||
},
|
||||
setValues(){
|
||||
|
|
|
@ -47,7 +47,7 @@ export const fetchFields = ({ commit }, item_id) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const cleanFields = ({ commit }, item_id) => {
|
||||
export const cleanFields = ({ commit }) => {
|
||||
commit('cleanFields');
|
||||
};
|
||||
|
||||
|
|
|
@ -35,7 +35,21 @@ export const setItemsPerPage = ({ commit }, page ) => {
|
|||
|
||||
// Sorting queries
|
||||
export const setOrderBy = ({ commit }, orderBy ) => {
|
||||
commit('setPostQueryAttribute', { attr: 'orderby', value: orderBy } );
|
||||
if (orderBy.field_type == 'Tainacan\\Field_Types\\Numeric') {
|
||||
commit('addMetaQuery', {
|
||||
field_id: orderBy.id
|
||||
});
|
||||
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
|
||||
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value_num' } );
|
||||
} else if (orderBy.field_type == 'Tainacan\\Field_Types\\Core_Title') {
|
||||
commit('setPostQueryAttribute', { attr: 'orderby', value: 'title' } );
|
||||
} else {
|
||||
commit('addMetaQuery', {
|
||||
field_id: orderBy.id
|
||||
});
|
||||
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
|
||||
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value' } );
|
||||
}
|
||||
};
|
||||
|
||||
export const setOrder = ({ commit }, order ) => {
|
||||
|
|
Loading…
Reference in New Issue