XF 2.2 Ajax loaded template and formrows rendering

Scandal

Well-known member
Hello all! (y)

I have a question about ajax loaded content (template).

I use this code to get some ajax loaded content:
JavaScript:
    var ajaxParams = {'act': 'test'};
    XF.ajax('post', "{{ link_type('admin', 'canonical:myroute', null) }}", ajaxParams, function(data, textStatus, jqXHR){
        $('#mydiv').append(data.output);
    });
The php side has this:
PHP:
$this->setResponseType('json');
$html = \XF::app()->templater->renderTemplate('admin:sc_mytemplate', []);    
$output = ['output' => $html];            
echo json_encode($output);
exit;

The problem: sc_mytemplate has some formrow items like <xf:numberbox>, which are not rendered as "should".

Instead of this:
normal.png
I'm getting this:
problem.png

It seems that <xf:numberbox> is not rendering correctly, maybe due to javascript and ajax way I decided to load this template.

Any idea how to fix it or for a xF2 more normalized way? :)
 
Just return a normal view from the PHP side. There shouldn't be a need for special handling.

JavaScript:
var ajaxParams = {'act': 'test'};
XF.ajax(
    'post', 
    "{{ link_type('admin', 'canonical:myroute', null) }}", 
    ajaxParams, 
    function(data)
    {
        XF.setupHtmlInsert(data.html, function($html)
        {
            $('#mydiv').append($html);
        }
    }
);
 
Back
Top Bottom