Skip to content

Commit

Permalink
Merge pull request #14 from workupsrl/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rslanzi authored May 9, 2024
2 parents 9631a26 + 838ac92 commit ab2dc62
Show file tree
Hide file tree
Showing 5 changed files with 5,115 additions and 5,004 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## [4.2.1] - 2024-05-09
### Fixed
- Fix translation on media fields

## [4.2.0] - 2024-02-08
### Added
- Translatable SEO attributes for images
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions resources/js/components/fields/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</a>
<div class="flex flex-row items-center">
<gallery slot="value" ref="gallery" v-if="hasSetInitialValue"
v-model="value" :editable="!field.readonly" :removable="field.removable"
custom-properties :field="field" :multiple="field.multiple"
v-model="gallery" :editable="!field.readonly" :removable="field.removable"
custom-properties :field="field" :multiple="field.multiple && !field.single"
:uploads-to-vapor="field.uploadsToVapor"
:has-error="hasError" :first-error="firstError"/>
</div>
Expand Down Expand Up @@ -62,6 +62,7 @@ export default {
existingMediaOpen: false,
locales: Object.keys(this.field?.locales || {}),
currentLocale: null,
gallery: [],
}
},
mounted() {
Expand All @@ -71,6 +72,8 @@ export default {
this.changeTab(locale, true);
}
});
this.gallery = this.displayValue
},
computed: {
openExistingMediaLabel() {
Expand All @@ -88,6 +91,11 @@ export default {
: this.value
},
},
watch: {
gallery(gallery) {
this.handleChange(gallery)
},
},
methods: {
changeTab(locale, dontEmit) {
if (this.currentLocale !== locale) {
Expand All @@ -96,6 +104,8 @@ export default {
}
this.currentLocale = locale;
this.gallery = this.displayValue
}
},
/*
Expand All @@ -104,7 +114,7 @@ export default {
setInitialValue() {
let value = this.field.value || [];
if (!this.field.multiple && !this.field.translatable) {
if ((!this.field.multiple || this.field.single) && !this.field.translatable) {
value = value.slice(0, 1);
}
Expand Down Expand Up @@ -181,12 +191,19 @@ export default {
addExistingItem(item) {
let copiedArray = this.value.slice(0)
if (!this.field.multiple && !this.field.translatable) {
if ((!this.field.multiple || this.field.single) && !this.field.translatable) {
copiedArray.splice(0, 1);
} else if (this.field.single && this.field.translatable) {
const index = copiedArray.findIndex((element) => {
return element.custom_properties.locale === this.currentLocale;
});
copiedArray.splice(index, index >= 0 ? 1 : 0);
}
copiedArray.push(_.set(item, 'custom_properties.locale', this.currentLocale));
this.value = copiedArray
this.gallery = this.displayValue
}
},
};
Expand Down
9 changes: 9 additions & 0 deletions src/Fields/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,13 @@ public function seoAttributes(): self

return $this;
}

/**
* Force the field to accept only one media
* @return self
*/
public function single(): self
{
return $this->withMeta(['single' => true]);
}
}
Loading

0 comments on commit ab2dc62

Please sign in to comment.