Ad

OctoberCms - Model Filter Field Depends On Filter Field

- 1 answer

I have a filtered field depending on a filtered field: ...

basket:
    label: Basket
    prompt: 'Add Item'
    span: full
    type: repeater
    form:
        fields:
            item:
                label: Item
                emptyOption: 'Select Product'
                showSearch: true
                span: auto
                type: dropdown
            totalprice:
                label: 'Total Price'
                span: right
                readOnly: 1
                dependsOn:
                    - item
                type: number

subtotal:
    label: 'Sub Total'
    span: auto
    default: ''
    readOnly: 1
    dependsOn:
        - basket
    type: number

The idea is that when an item within the basket is updated, the total price for that item updates which causes the basket to update. this then makes the subtotal for the basket update.

The total price for each item updates fine no issues at all. However, the subtotal seems to always be one update behind. I believe this is because the fields are only actually updates at the end of the filterfields function?

Is there anyway to allow filterfields dependant on filtered fields?

Ad

Answer

To my experience repeater are a quick, but not the ideal solution for tasks as you are describing. A related 'basketitem' table with a belongsTo (baskitem belongsTo bask, bask hasMany baskitems) could solve your problem. And by the way there is a tutorial to use as a pattern at https://octobercms.com/support/article/ob-21

Ad
source: stackoverflow.com
Ad