Skip to content

Commit

Permalink
Merge pull request #1152 from dev-lnk/show-when-js
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to authored Aug 9, 2024
2 parents c19c2be + 34e565d commit 6dd92a8
Show file tree
Hide file tree
Showing 16 changed files with 295 additions and 115 deletions.
56 changes: 30 additions & 26 deletions resources/js/Components/FormBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import request from '../Request/Core.js'
import {dispatchEvents as de} from '../Support/DispatchEvents.js'
import {
getInputs,
isValidateShow,
showWhenChange,
showWhenVisibilityChange,
} from '../Support/ShowWhen.js'
Expand Down Expand Up @@ -85,37 +84,44 @@ export default (name = '', initData = {}, reactive = {}) => ({
}
})

if (t.whenFields !== undefined) {
this.$nextTick(async function () {
let formId = t.$id('form')
if (formId === undefined) {
formId = t.$el.getAttribute('id')
}
this.whenFieldsInit()
},
whenFieldsInit(){
const t = this

await t.$nextTick()
if (! t.whenFields.length) {
return
}

const inputs = t.getInputs(formId)
this.$nextTick(async function () {
let formId = t.$id('form')
if (formId === undefined) {
formId = t.$el.getAttribute('id')
}

const showWhenConditions = {}
await t.$nextTick()

t.whenFields.forEach(field => {
if (
const inputs = t.getInputs(formId)

const showWhenFields = {}

t.whenFields.forEach(field => {
if (
inputs[field.changeField] === undefined ||
inputs[field.changeField].value === undefined
) {
return
}
if (showWhenConditions[field.showField] === undefined) {
showWhenConditions[field.showField] = []
}
showWhenConditions[field.showField].push(field)
})

for (let key in showWhenConditions) {
t.showWhenVisibilityChange(showWhenConditions[key], key, inputs, formId)
) {
return
}
if (showWhenFields[field.showField] === undefined) {
showWhenFields[field.showField] = []
}
showWhenFields[field.showField].push(field)
})
}

for (let key in showWhenFields) {
t.showWhenVisibilityChange(showWhenFields[key], key, inputs, formId)
}
})
},
precognition() {
const form = this.$el
Expand Down Expand Up @@ -276,8 +282,6 @@ export default (name = '', initData = {}, reactive = {}) => ({

showWhenVisibilityChange,

isValidateShow,

getInputs,
})

Expand Down
6 changes: 6 additions & 0 deletions resources/js/Components/TableBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export default (

this.table.querySelector('tbody').appendChild(this.lastRow.cloneNode(true))

const form = this.table.closest('from[data-component]')
if(form) {
const formName = form.getAttribute('data-component')
this.$dispatch('show_when_refresh:' + formName)
}

if (!force && this.reindex) {
this.resolveReindex()
}
Expand Down
4 changes: 2 additions & 2 deletions resources/js/Support/Forms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {inputFieldName, inputGeValue} from './ShowWhen.js'
import {inputFieldName, inputGetValue} from './ShowWhen.js'

export function filterAttributeStartsWith(data, startsWith) {
const filtered = {}
Expand Down Expand Up @@ -97,7 +97,7 @@ export function crudFormQuery(formElements = null) {
!name.startsWith('_') &&
!name.startsWith('hidden_')
) {
values[inputFieldName(name)] = inputGeValue(element)
values[inputFieldName(name)] = inputGetValue(element)
}
})

Expand Down
Loading

0 comments on commit 6dd92a8

Please sign in to comment.