Validation (#216)
* Field config options: 'required' and 'pattern' * Widget controls can implement it's own isValid * Validation errors store in redux & displayed * Support for returned Promises in isValid * Allow widget controls to return either a boolean, an error object or a promise from isValid
This commit is contained in:
@ -219,9 +219,14 @@ export function loadUnpublishedEntries() {
|
||||
};
|
||||
}
|
||||
|
||||
export function persistUnpublishedEntry(collection, entryDraft, existingUnpublishedEntry) {
|
||||
export function persistUnpublishedEntry(collection, existingUnpublishedEntry) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const entryDraft = state.entryDraft;
|
||||
|
||||
// Early return if draft contains validation errors
|
||||
if (!entryDraft.get('fieldsErrors').isEmpty()) return;
|
||||
|
||||
const backend = currentBackend(state.config);
|
||||
const assetProxies = entryDraft.get('mediaFiles').map(path => getAsset(state, path));
|
||||
const entry = entryDraft.get('entry');
|
||||
|
@ -24,6 +24,7 @@ export const DRAFT_CREATE_EMPTY = 'DRAFT_CREATE_EMPTY';
|
||||
export const DRAFT_DISCARD = 'DRAFT_DISCARD';
|
||||
export const DRAFT_CHANGE = 'DRAFT_CHANGE';
|
||||
export const DRAFT_CHANGE_FIELD = 'DRAFT_CHANGE_FIELD';
|
||||
export const DRAFT_VALIDATION_ERRORS = 'DRAFT_VALIDATION_ERRORS';
|
||||
|
||||
export const ENTRY_PERSIST_REQUEST = 'ENTRY_PERSIST_REQUEST';
|
||||
export const ENTRY_PERSIST_SUCCESS = 'ENTRY_PERSIST_SUCCESS';
|
||||
@ -141,6 +142,7 @@ export function createDraftFromEntry(entry) {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function discardDraft() {
|
||||
return {
|
||||
type: DRAFT_DISCARD,
|
||||
@ -161,6 +163,14 @@ export function changeDraftField(field, value, metadata) {
|
||||
};
|
||||
}
|
||||
|
||||
export function changeDraftFieldValidation(field, errors) {
|
||||
return {
|
||||
type: DRAFT_VALIDATION_ERRORS,
|
||||
payload: { field, errors },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Exported Thunk Action Creators
|
||||
*/
|
||||
@ -213,9 +223,14 @@ export function createEmptyDraft(collection) {
|
||||
};
|
||||
}
|
||||
|
||||
export function persistEntry(collection, entryDraft) {
|
||||
export function persistEntry(collection) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const entryDraft = state.entryDraft;
|
||||
|
||||
// Early return if draft contains validation errors
|
||||
if (!entryDraft.get('fieldsErrors').isEmpty()) return;
|
||||
|
||||
const backend = currentBackend(state.config);
|
||||
const assetProxies = entryDraft.get('mediaFiles').map(path => getAsset(state, path));
|
||||
const entry = entryDraft.get('entry');
|
||||
|
Reference in New Issue
Block a user