A
A
amorphine2017-12-09 10:22:25
CMS
amorphine, 2017-12-09 10:22:25

How to natively update form fields for a pivot model in OctoberCMS via AJAX (manage step)?

Comrades Octobrists, please help.
There is such a page in the admin panel (Route model + pivots for City and Sight)

5a2b8f81c3aad848697573.png

Everything is fine, when we click Add Sight - it offers a list of available Sights, click on any, proceed to configure additional fields of the Pivot table.

5a2b8da28d31f761269123.png

I didn’t come up with anything smarter than how to render a button from a widget:
Here it is connected to plugins/xdim/tripmagik/ models/routesightpivot/fields.yaml

fields:
    pivot[sort]:
        label: Order
        type: number
        span: auto
    pivot[time_from_start_to_sight]:
        label: Time from start to the sight
        type: number
        span: auto
    pivot[add_route_time]:
        label: Add time
        type: number
        span: auto
    pivot[add_route_price]:
        label: Basic add. price
        type: number
        span: auto
    pivot[stay_time_default]:
        label: Default stay time
        type: number
        span: auto
    pivot[stay_time_min]:
        label: Min. stay time
        type: number
        span: auto
    pivot[stay_price]:
        label: Price per quarter of hour
        type: number
        span: auto
    _gmaps_sync:
        label: You may try to get data from Google Maps API
        type: gmapsroutesightsync
        commentAbove: Make sure you have entered Google Maps API key


I can assign an ajax handler to the button, but here the most obscure begins: the following data from POST gets into the handler in the controller or widget

5a2b8e998065f398258830.png

: But I have a feeling that all this is not native and some kind of crutchism.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Kornilov, 2017-12-09
@amorphine

How to natively update form fields via AJAX

1. Make your handler on the server, which will receive all the data you need to update
2. Access it natively via AJAX , get a response with data
3. Display data on the page
If any of these points is not clear, then formulate a question. CMS is not familiar to me, so I can only help with well-known technologies. Perhaps someone will answer in more detail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question