This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

wimalaya
wimalaya

The data-request-update attribute doesn't work in component partial 'default.htm'. The partial doesn't update itself! I get only a page refresh. Why? This is my form and partial rendering in default.htm:

<form class="form-inline" data-request="onChangeResult" data-request-update="{{__SELF__}}::result: '#result-div'">
    <input type="text" class="form-control" value="15" name="value">
    <button type="submit" class="btn btn btn-primary">Calculate</button>
</form>
<div  id="result-div">{% partial __SELF__~'::result' %}</div>

This is my code in result.htm (another partial in component partial directory, the same directory of default.htm):

<span class="result">{{ result }}</span>

Finally this is the function in component php file:

function onChangeResult() {
    $value = post('value');
    $this->page['result'] = $value;
 }

What am I doing wrong? Maybe the reference to partial result.htm? Thanks!

UPDATE: the problem is the partial name {{ __SELF__ }}::result in data-request-update, but if i put only result, the partial isn't found. How can I reference component partial in default.htm? It is possible? If not, how can I do?

Last updated

wimalaya
wimalaya

I resolved putting the update inside the function onChangeResult():

function onChangeResult() {
    $value = post('value');
    $this->page['result'] = $value;
    return ['#result-div' => $this->renderPartial('component::result')];
 }

and I remove data-request-update attribute in form.

Last updated

leonardfactory
leonardfactory

For anyone who is still interest in using data-request-update to update a partial, writing component::partial inside the attribute worked for me, i.e.:

{{ form_ajax('onSearch', { update: { 'myComponent::myPartial': '#partial-element' } }) }}
Dmitry
Dmitry

I think you forget to pass a variable to partial view {% partial SELF~'::result' result= result %}

evianoa15013
evianoa15013

@leonardfactory thanks for your post; It came in very useful for me.

pain-spark50564
pain-spark50564

wimalaya said:

I resolved putting the update inside the function onChangeResult():

function onChangeResult() { $value = post('value'); $this->page['result'] = $value; return ['#result-div' => $this->renderPartial('component::result')]; }

and I remove data-request-update attribute in form.

you have success ? I need help to do this ....

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.