Skip to content

Commit

Permalink
Merge pull request #207 from marcfilipan/master
Browse files Browse the repository at this point in the history
Fixed that errors on form submissions are now reflected on tabs
  • Loading branch information
marcfil authored May 13, 2022
2 parents 2771e26 + 0cf734a commit 84980cb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2.0.5 - 2022-05-13
- Fixed that errors on form submissions are now reflected on tabs

## 2.0.4 - 2022-05-13
- Fixed padding issues
- Fixed codemirror fields and styles
Expand Down
2 changes: 1 addition & 1 deletion dist/css/field.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions resources/css/field.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ form .tab-group .tab.fields-tab {
.tab-group h1 + .flex + div {
@apply tabs-shadow-none tabs-rounded-t-none tabs-rounded-b-lg;
}
.tab-has-error {
@apply tabs-text-red-500 tabs-border-b-2 tabs-border-b-red-500 !important
}
.tab-has-error:after {
content: ' *';
}
7 changes: 5 additions & 2 deletions resources/js/components/FormTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
<a
v-for="(tab, key) in getSortedTabs(tabs)"
:key="key"
:class="getIsTabCurrent(tab) ? 'active text-primary-500' : 'tabs-text-gray-800 dark:tabs-text-gray-50'"
:class="getIsTabCurrent(tab) ? 'active text-primary-500 tabs-border-2 border-primary-500' : 'tabs-text-gray-800 dark:tabs-text-gray-50'"
:dusk="tab.slug + '-tab'"
:ref="tab.slug + '-tab'"
class="tab-item"
@click.prevent="handleTabClick(tab)"
>
<span class="capitalize">{{ tab.properties.title }}</span>
<span
<!--
<span
v-if="getIsTabCurrent(tab)"
aria-hidden="true"
class="bg-primary-500 tabs-absolute tabs-inset-x-0 tabs-bottom-0 tabs-h-0.5"
Expand All @@ -42,6 +44,7 @@
aria-hidden="true"
class="tabs-bg-transparent tabs-absolute tabs-inset-x-0 tabs-bottom-0 tabs-h-0.5"
></span>
-->
</a>
</nav>
</div>
Expand Down
33 changes: 32 additions & 1 deletion resources/js/mixins/HasTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default {
if (event?.detail?.visit?.url) {
let currPath = window.location.pathname;
let newPath = event?.detail?.visit?.url?.pathname;

currPath = currPath.substring(currPath.length - 5) === "/edit" ? currPath.substring(0, currPath.length - 5) : currPath;
newPath = newPath.substring(newPath.length - 5) === "/edit" ? newPath.substring(0, newPath.length - 5) : newPath;

Expand All @@ -110,6 +110,18 @@ export default {
});
Nova.store.tabsListenerRegistered = true;
}

this.$watch('validationErrors', (newErrors) => {
if (newErrors.errors) {
Object.entries(newErrors.errors).forEach(error => {
if (error[0] && this.fields.find(x => x.attribute === error[0])) {
let field = this.getNestedObject(this.fields, 'attribute', error[0]);
let slug = this.getNestedObject(this.fields, 'attribute', error[0]).tabSlug + '-tab';
this.$refs[slug][0].classList.add('tab-has-error')
}
});
}
})
},

methods: {
Expand Down Expand Up @@ -273,6 +285,25 @@ export default {
*/
getSortedTabs(tabs) {
return orderBy(tabs, [c => c.position], ['asc']);
},

/**
* Get nested object with specified key from object
*
* @param entireObj
* @param keyToFind
* @param valToFind
* @returns {*}
*/
getNestedObject(entireObj, keyToFind, valToFind) {
let foundObj;
JSON.stringify(entireObj, (_, nestedValue) => {
if (nestedValue && nestedValue[keyToFind] === valToFind) {
foundObj = nestedValue;
}
return nestedValue;
});
return foundObj;
}

},
Expand Down

0 comments on commit 84980cb

Please sign in to comment.