farinspace / wpalchemy

Thin framework for wordpress
http://wpalchemy.com/
Other
416 stars 110 forks source link

wp_editor and Repeating Fields #84

Open armandmorin opened 10 years ago

armandmorin commented 10 years ago

Has anyone got wp_editor and repeating fields to work. It repeats but nothing is there.

The reason I want to get this working is in the next version of WordPress 3.9 it will have TinyMCE 4.0 which breaks the customEditor way of adding the editor. I just found this out today.

http://make.wordpress.org/core/2014/01/18/tinymce-4-0-is-in-core/

So I need to make wp_editor work in repeating fields which makes sense anyway.

Any ideas?

foxydot commented 10 years ago

I may have something working. I'm still doing some testing, but I think the problem lies here: " $editor_id (string) (required) HTML id attribute value for the textarea and TinyMCE. (may only contain lower-case letters)

    Default: None 

" When you try to pass $mb->get_the_name(), it inputs all kinds of brackets and such, which are disallowed characters. Here's where I'm at: https://gist.github.com/foxydot/9075575 Using sanitize_key removes those illegal characters. Adding 'textarea_name'=>$mb->get_the_name() to the settings array re-targets the input to that hidden textbox. I'm using Extract Mode (I always do, for searchability) and so far it seems to be working.

armandmorin commented 10 years ago

Very cool... I'll try it today and let you know how it works.

AlchemyCompSol commented 10 years ago

Thanks, foxydot! That worked for me!

armandmorin commented 10 years ago

I've tried the solution, but when I duplicate the wp_editor I can't click or type in it. Is anyone else experiencing this? or am I missing something.

foxydot commented 10 years ago

I know I've had some issues with this when I'm modifying re-purposed older code and my copy of WPAlchemy is older. Make sure you have the latest version of the core scripts. Also, I haven't tested the solution on IE at all. I yell at my clients if they use IE for editing. ;D (Im a mean mommy)

armandmorin commented 10 years ago

Still no go... Here's what I have....

To create the metabox I am using Extract mode as you are

$features_metabox = new WPAlchemy_MetaBox( array( 
    'id' => '_wpsl_features', 
    'title' => 'Features and Benefits', 
    'types' => array( 'salesletters' ), 
    'template' => WP_PLUGIN_DIR . '/wp-sales-letter/metaboxes/features-mb.php',
    'mode' => WPALCHEMY_MODE_EXTRACT,
    'prefix' => '_my_'
     )
 );

I'm also using this to create the repeating fields

<?php while( $mb->have_fields_and_multi( 'features' ) ): ?>
<?php $mb->the_group_open(); ?>

    <div id='wpsl_features' style="border:1px solid #ccc;padding:10px;border-radius:2px; margin-bottom: 20px;">
        <?php $mb->the_field( 'thefeature' ); ?>
        <label>Feature</label><div class='description'>Enter the name of the feature you want to talk about.</div>
        <p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>" /></p>

        <?php
        $mb->the_field('benefit');
        $mb_content = html_entity_decode($mb->get_the_value(), ENT_QUOTES, 'UTF-8');
        $mb_editor_id = sanitize_key($mb->get_the_name());
        $mb_settings = array('textarea_name'=>$mb->get_the_name(),'textarea_rows' => '5',);
        wp_editor( $mb_content, $mb_editor_id, $mb_settings );
        ?>

        <a style="margin-bottom: 20px;" href="#" class="dodelete button">Delete Feature</a>
        <p></p>
     </div>

<?php $mb->the_group_close(); ?>
<?php endwhile; ?>

Can anyone see anything I'm doing wrong?

The issue is foxydot's code creates the wp_editor just fine, but I cannot click in the area. I can click on the text tab but it then displays the editor very funky. Very strange.

Any help would be great. I can't think of anything else.

foxydot commented 10 years ago

your code looks exactly like what worked for me. I'm guessing you tested this on a raw install of WP as well to cancel out other plugins and theme issues. It almost sounds like a javascript issue. :/

one thing i might try is removing the html entity thing (because you mentioned the text side is displaying funky.) to just

    $mb_content = $mb->get_the_value();

but that's a bit of a stretch.

armandmorin commented 10 years ago

One thing I think I neglected to say... I am using... 3.9-alpha-27234 Are you using 3.8.1 or the beta 3.9?

foxydot commented 10 years ago

3.8.1. hrm. that might mean I'll have to fix my code again on upgrade. I'll check that out.

armandmorin commented 10 years ago

I found a clue. It has to do with the visual editor. If the editor is set to the "Text" tab and you try to copy group it works fine and you can type inside it, but... if editor is set on the Visual Tab, it copies, but you cannot click in the area. I'm trying some options now to see if I can get it to work.

helgatheviking commented 10 years ago

For anyone still following this, I've updated my Holy Grail child theme which demonstrates working repeatable, sortable tiny MCE fields.