Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax without Pjax? #100

Closed
siliconalchemy opened this issue Nov 23, 2015 · 3 comments
Closed

Ajax without Pjax? #100

siliconalchemy opened this issue Nov 23, 2015 · 3 comments

Comments

@siliconalchemy
Copy link

Hi

Like others I'm struggling to get editable working within content loaded through ajax. I don't want to/can't use pjax. This is a great general interface plugin but a bit limited if it doesn't work with vanilla jquery/ajax.

Is there some sample code or a pointer in the right direction?

@kartik-v
Copy link
Owner

Techincally its possible for ajax as well. You as the developer needs to write the necessary JS code to initialize the plugin after you have overwritten the HTML markup via AJAX (that will break the jquery bindings). In some cases (depending on your design) using yii's renderAjax method to overwrite the HTML can help as the widget will try to reinitialize itself.

@kartik-v
Copy link
Owner

An enhancement has been provided - you can use the plugin's destroy and create methods via enhancement #87. Also an initEditablePopover method has been provided where you can pass the toggleButton reference id to initialize popover after ajax replace.

@nadirvishun
Copy link

nadirvishun commented Jun 16, 2018

Thanks for this widget.
I have the same question in ajax load without pjax。
assume id is unique id like status-1 or something

  $("#"+id+"-cont").editable("destroy").editable("create");
  initEditablePopover("#"+id+"-targ");

but I should initable the options,assume the option object is editable_a690100c ,it's value like:

window.editable_eaca81be = {"valueIfNull":"not set","asPopover":true,"placement":"left","target":".kv-editable-link","displayValueConfig":[],"ajaxSettings":[],"showAjaxErrors":true,"submitOnEnter":true,"selectAllOnEdit":true,"encodeOutput":true,"closeOnBlur":false,"validationDelay":500,"resetDelay":200,"animationDelay":300};

so ,I should add this for init:

$("#"+id+"-cont").editable(editable_a690100c)

but how can get the hash a690100c? in some other widget like switchinput ,we can get the hash like this:

var opts = window[$("#"+id).attr("data-krajee-bootstrapSwitch")];
$("#"+id).bootstrapSwitch(opts);

but in editable widget ,I can not get the hash
please help me how to resolve this prombles.


maybe ,we should add this code in Editable.php in function initEditable:

...
 Config::validateInputWidget($this->inputType);
        $this->initI18N(__DIR__);
        $this->initOptions();
        $this->_popoverOptions['options']['id'] = $this->options['id'] . '-popover';
        $this->_popoverOptions['toggleButton']['id'] = $this->options['id'] . '-targ';
        $this->registerAssets();
        //add this line in below
        $this->_popoverOptions['toggleButton']['data-krajee-editable'] = $this->options['data-krajee-editable'];
        echo Html::beginTag('div', $this->containerOptions);
        if ($this->format == self::FORMAT_BUTTON) {
            echo Html::tag('div', $this->displayValue, $this->editableValueOptions);
        }
...

maybe this issue closed, and can not get the reply, so I open a new issue ,see #175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants