michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
337 stars 71 forks source link

Widgets not saving #202

Closed vladkucherov closed 9 years ago

vladkucherov commented 9 years ago

Hi,

I found that the widgets are not saved properly. I tried to edit a widget that has a textarea / Ace Editor, after I tried to save the changes, the widget returned to it's previous state with previous content. only after that it saved my changes.

In the case of Ace Editor - I save the content, it's not saved and the editor disappears without any JS error. After it turned to a textarea - it will save.

Ideas?

michaeluno commented 9 years ago

Try only with the textarea field type by replacing type => 'ace' to type => 'textarea and see if the problem that the widget form data are not saved persists. If the data stat getting saved, it is likely an issue of the ACE field type which is not compatible with widget forms.

vladkucherov commented 9 years ago

@michaeluno Yes, you are right. I tried the textarea and it worked. Any ideas on why this is happening?

michaeluno commented 9 years ago

By glancing at the code, it could be unescaped characters.

This part

                    . "<textarea " . $this->generateAttributes( $aInputAttributes  ) . " >" 
                            . $aField['value']
                    . "</textarea>"

May have to be

                    . "<textarea " . $this->generateAttributes( $aInputAttributes  ) . " >" 
                            . esc_textarea( $aField['value'] )
                    . "</textarea>"
vladkucherov commented 9 years ago

Doesn't seem to help.

Note that after I save, the editor is changed to a textarea, maybe that's the problem?

michaeluno commented 9 years ago

Sounds like the field type does not renew the event binding of the editor script after the form is saved. In that case, it's not compatible with widget forms. You should ask Per to support it.

vladkucherov commented 9 years ago

@michaeluno I fixed this issue by binding the addAceEditor to widget-updated event.

jQuery(document).on('widget-updated', function(e, widget){
    jQuery('textarea[data-ace_language]').each(function () {
        addAceEditor(jQuery(this));
    });
});

But the data is still not stored. I looked at the headers, and for some reason it sends the original content, not the latest one I just edited.

vladkucherov commented 9 years ago

@michaeluno You can participate if you wish. https://github.com/soderlind/AceCustomFieldType/pull/1

soderlind commented 9 years ago

Thank you, I've merged soderlind/AceCustomFieldType#1

vladkucherov commented 9 years ago

I think we'll move this issue to here https://github.com/soderlind/AceCustomFieldType/issues/2

vladkucherov commented 9 years ago

https://github.com/soderlind/AceCustomFieldType/pull/3

Fixed that :smile:

michaeluno commented 9 years ago

Glad to hear you sorted it out!