Skip to content

Commit

Permalink
Merge pull request #23 from razorcreations/release/1.3.0
Browse files Browse the repository at this point in the history
Fix parent option passing to ajax endpoint
  • Loading branch information
Stowez authored Nov 14, 2024
2 parents 64eaaeb + 0dfdcfb commit 23e9157
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 29 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 1.3.0 - 2024-11-14

- Fixed selected parent option not being passed correctly to the ajax endpoint
- Added Custom stylesheet to help dark mode conflicts

## 1.2.3 - 2024-11-06

- Updated dist bundle
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "razorcreations/ajax-field",
"description": "A searchable AJAX powered field for Laravel Nova 3 and 4.",
"version": "1.2.3",
"version": "1.3.0",
"authors": [
{
"name": "Ross Cooper",
Expand Down
2 changes: 1 addition & 1 deletion dist/css/field.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@

.dark .vs--single .vs__selected{color:#0f0!important}
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"/js/field.js": "/js/field.js"
"/js/field.js": "/js/field.js",
"/css/field.css": "/css/field.css"
}
3 changes: 3 additions & 0 deletions resources/css/field.css
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/* Nova Field CSS */
.dark .vs--single .vs__selected {
color: #0f0!important;;
}
63 changes: 39 additions & 24 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,6 @@ export default {
},
computed: {
parentComponent() {
if (!this.field.parent_field) {
return false;
}
let targetField = this.field.parent_field;
let currentField = this.field.attribute;
// If component is inside a flexible, key is prefixed with an id
if (currentField.indexOf('__')) {
targetField = currentField.substr(0, currentField.indexOf('__')) + '__' + targetField;
}
if (typeof this.$parent.$children === 'undefined') {
return;
}
// Find the component the parent value references
return this.$parent.$children.find(component => {
return component.field !== undefined
&& component.field.attribute == targetField;
})
},
availableOptions() {
return _.uniqBy(this.options.concat(this.selectedOptions), 'value');
},
Expand All @@ -94,6 +70,45 @@ export default {
},
methods: {
findParentField() {
let parentFieldTarget = this.field.parent_field;
let currentField = this.field.attribute;
// If component is inside a flexible, key is prefixed with an id taken from currentField
if (currentField.indexOf('__') > -1) {
parentFieldTarget = currentField.substr(0, currentField.indexOf('__')) + '__' + parentFieldTarget;
}
// Make some attempts to find the parent field
const parentField = document.querySelector(`.form-input#${parentFieldTarget}`);
if (parentField) {
return parentField;
}
return null;
},
observeParentField() {
const targetInput = this.findParentField();
if (!targetInput) {
console.warn(`Input field with id ${this.field.parent_field} not found`);
return;
}
// Set initial value
this.parentVal = targetInput.value;
// Event listener to detect input changes
const updateParentValue = (event) => {
this.parentVal = event.target.value;
this.options = [];
this.loadInitialOptions();
};
targetInput.addEventListener('input', updateParentValue);
},
prepareField() {
//Check whether any filterable data was set, otherwise stay true
if (typeof this.field.filterable !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.3
1.3.0
1 change: 1 addition & 0 deletions webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let mix = require('laravel-mix')

mix.setPublicPath('dist')
.js('resources/js/field.js', 'js')
.css('resources/css/field.css', 'css')
.vue({version: 3})
.webpackConfig({
externals: {
Expand Down

0 comments on commit 23e9157

Please sign in to comment.