kartik-v / yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0
http://demos.krajee.com/markdown
Other
89 stars 41 forks source link

Export conflict with ActiveForm #16

Closed drenty closed 10 years ago

drenty commented 10 years ago

EDIT BY KARTIK: Changed title to Export conflict with ActiveForm. Original title was Client side validation issue.

Hello Kartik,

Client-side validation doesn't work anymore. Is it just me?

When I replace the widget by a textarea the validation works.

kartik-v commented 10 years ago

Client side validation should work only if you are using with active form. Something like $form->field($model, $attrib)->widget(MarkdownEditor::classname(), $options);

How are you using the widget?

drenty commented 10 years ago

Oh yeah my bad. I was using it this way:

echo \kartik\markdown\MarkdownEditor::widget([
    'model' => $model, 
    'attribute' => 'content',
]);

Client-side validation works now but I cannot submit the form (with a plain TextArea I can).

kartik-v commented 10 years ago

You need to debug your code for errors? What error messages are you receiving?

drenty commented 10 years ago

I don't have any JS error.

I think there is a problem with your recent changes in renderExportForm() which seem to break the submit button.

When I set showExport to false or put my Submit button before the widget, I can submit the form.

I don't know if it's the nested forms or what. The nested form doesn't even appear in the DOM (I'm using Chrome).

kartik-v commented 10 years ago

Pushed in a fix. Check and let know.

drenty commented 10 years ago

Shouldn't the export form be inside the iframe? If I change your code to do this it works fine.

kartik-v commented 10 years ago

Are you facing the same error after the fix? The form submission target is set to the iframe and when the plugin is initialized, the form is automatically removed and appended at the end of the body via javascript. So you should not face the nested form issue.

If you are facing any error can you post the log/screenshot? If you are fixing it with some code can you please post the same as well?

drenty commented 10 years ago

Yes I'm facing the exact same issue. The submit button seems to be disabled.

Here is my DOM:

image

The quick hack I did that seems to work:

protected function renderExportForm()
{
    $action = $this->_module->downloadAction;
    if (!is_array($action)) {
        $action = [$action];
    }
    $frameId = $this->options['id'] . '_export';
    $iframe = '<iframe style="width: 0px; height: 0px;" scrolling="no" frameborder="0" border="0" id="' . $frameId .'" name="' . $frameId . '">';
    return $iframe . Html::beginForm($action, 'post', ['class' => 'kv-export-form', 'style' => 'display:none', 'target' => $frameId]) .
    Html::textInput('export_filetype', '', ['style' => 'display:none']) .
    Html::textInput('export_filename', '', ['style' => 'display:none']) .
    Html::textArea('export_content', '', ['style' => 'display:none']) .
    Html::endForm() .
    '</iframe>';
}
kartik-v commented 10 years ago

The hack above would disable export & file download functionality itself - since the code will never be able to locate the export form for submission. Have you checked that?

Also IMHO -- the iframe contents cannot be framed that way. An iframe needs a src attribute (url) to generate the contents.

kartik-v commented 10 years ago

Revamped code with latest commit. Making it work cross browsers, especially with IE was tricky - but looks like its resolved. Check and update. This should resolve few issues:

drenty commented 10 years ago

The submit button works now however I still have the following issues on Chrome:

On Firefox it works but the files have no name nor extension.

kartik-v commented 10 years ago

I don't know if you have the latest version (or is it a caching problem with your environment). It seems to work fine on all browsers.

You can validate this on the demo site for usage with ActiveForm here. It also has a submit and reset button, with CLIENT VALIDATION (try setting the notes field to blank for example). You can check this from your browsers and update.

drenty commented 10 years ago

You're right, it was a caching problem.

I just cleared all my assets and it works great, thank you :)