Skip to content

Commit af777a9

Browse files
committed
simplify requirement logic
1 parent ac10ff5 commit af777a9

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

resources/js/components/EntityDetail.vue

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -851,34 +851,22 @@
851851
let isValid = true;
852852
const dirtyValues = getDirtyValues(grps);
853853
854-
for(let attributeId in state.requiredAttributes) {
855-
const attribute = state.requiredAttributes[attributeId];
856-
854+
for(let attribute of state.requiredAttributes) {
855+
const dataExists = Boolean(state.entity.data[attribute.id]?.id);
856+
const isKeyInDirtyValue = hasKey(dirtyValues, attribute.id);
857+
const isDirtyValueEmpty = isEmpty(dirtyValues[attribute.id]);
857858
// check if existing value has an empty dirty value
858859
// -> delete operation
859-
if(
860-
state.entity.data[attribute.id]?.id
861-
&&
862-
hasKey(dirtyValues, attribute.id)
863-
&&
864-
isEmpty(dirtyValues[attribute.id])
865-
) {
860+
if(dataExists && isKeyInDirtyValue && isDirtyValueEmpty) {
866861
isValid = false;
867862
break;
868863
}
869864
// check if there is neither an existing valur nor:
870865
// a) an existing entry in dirty values
871866
// b) or the dirty value is empty
872867
// -> missing
873-
if(
874-
!state.entity.data[attribute.id]?.id
875-
&&
876-
(
877-
!hasKey(dirtyValues, attribute.id)
878-
||
879-
isEmpty(dirtyValues[attribute.id])
880-
)
881-
) {
868+
const noDirtyData = !isKeyInDirtyValue || isDirtyValueEmpty;
869+
if(!dataExists && noDirtyData) {
882870
isValid = false;
883871
break;
884872
}

0 commit comments

Comments
 (0)