mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-23 16:13:50 +00:00
FIX [review] implement changes based on review
This commit is contained in:
@@ -23,12 +23,7 @@ function loadDynamicPicker(element) {
|
||||
(input.value === '[]' || input.value === '') ?
|
||||
null : [ JSON.parse(input.value) ]
|
||||
)
|
||||
suggested = JSON.parse('[' + el.dataset.suggested + ']');
|
||||
// suggested = suggested[0];
|
||||
|
||||
console.log(typeof suggested)
|
||||
// console.log(el.dataset.suggested)
|
||||
console.log('suggested', typeof suggested[0])
|
||||
suggested = JSON.parse(el.dataset.suggested);
|
||||
|
||||
if (!isMultiple) {
|
||||
if (input.value === '[]'){
|
||||
@@ -58,13 +53,18 @@ function loadDynamicPicker(element) {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
addNewEntity(entity) {
|
||||
addNewEntity({entity, isSuggested = false}) {
|
||||
if (this.multiple) {
|
||||
if (!this.picked.some(el => {
|
||||
return el.type === entity.type && el.id === entity.id;
|
||||
})) {
|
||||
this.picked.push(entity);
|
||||
input.value = JSON.stringify(this.picked);
|
||||
console.log(entity)
|
||||
if (isSuggested) {
|
||||
const indexToRemove = this.suggested.findIndex(e => e.id === entity.id)
|
||||
this.suggested.splice(indexToRemove, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!this.picked.some(el => {
|
||||
@@ -76,9 +76,12 @@ function loadDynamicPicker(element) {
|
||||
}
|
||||
}
|
||||
},
|
||||
removeEntity(entity) {
|
||||
removeEntity({entity, isSuggested = false}) {
|
||||
this.picked = this.picked.filter(e => !(e.type === entity.type && e.id === entity.id));
|
||||
input.value = JSON.stringify(this.picked);
|
||||
if (isSuggested) {
|
||||
this.suggested.push(entity);
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
|
@@ -17,8 +17,7 @@
|
||||
</add-persons>
|
||||
</li>
|
||||
</ul>
|
||||
<ul v-if="Object.keys(suggested).length > 0" class="list-suggest add-items inline">
|
||||
<p>hello {{ Object.keys(suggested) }}</p>
|
||||
<ul class="list-suggest add-items inline">
|
||||
<li v-for="s in suggested" :key="s.id" @click="addNewSuggested(s)"><span>{{ s.text }}</span></li>
|
||||
</ul>
|
||||
</template>
|
||||
@@ -105,14 +104,12 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
addNewSuggested(entity) {
|
||||
this.$emit('addNewEntity', entity);
|
||||
const indexToRemove = this.suggested.findIndex(e => e.id === entity.id)
|
||||
this.suggested.splice(indexToRemove, 1);
|
||||
this.$emit('addNewEntity', {entity: entity, isSuggested: true});
|
||||
},
|
||||
addNewEntity({ selected, modal }) {
|
||||
selected.forEach((item) => {
|
||||
this.$emit('addNewEntity', item.result);
|
||||
}, this
|
||||
this.$emit('addNewEntity', { entity: item.result });
|
||||
}, this
|
||||
);
|
||||
this.$refs.addPersons.resetSearch(); // to cast child method
|
||||
modal.showModal = false;
|
||||
@@ -121,8 +118,7 @@ export default {
|
||||
if (!this.$props.removableIfSet) {
|
||||
return;
|
||||
}
|
||||
this.$emit('removeEntity', entity);
|
||||
this.suggested.push(entity);
|
||||
this.$emit('removeEntity',{ entity: entity, isSuggested: true });
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@@ -249,7 +249,11 @@
|
||||
|
||||
{% block pick_entity_dynamic_widget %}
|
||||
<input type="hidden" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value|escape('html_attr') }}" {% endif %} data-input-uniqid="{{ form.vars['uniqid'] }}"/>
|
||||
<div data-module="pick-dynamic" data-types="{{ form.vars['types']|json_encode }}" data-multiple="{{ form.vars['multiple'] }}" data-uniqid="{{ form.vars['uniqid'] }}" data-suggested="{{ form.vars['suggested'] }}"></div>
|
||||
<div data-module="pick-dynamic"
|
||||
data-types="{{ form.vars['types']|json_encode }}"
|
||||
data-multiple="{{ form.vars['multiple'] }}"
|
||||
data-uniqid="{{ form.vars['uniqid'] }}"
|
||||
data-suggested="{{ form.vars['suggested']|json_encode|escape('html_attr') }}"></div>
|
||||
{% endblock %}
|
||||
|
||||
{% block pick_postal_code_widget %}
|
||||
|
Reference in New Issue
Block a user