1

i've some problem with customization of quick edit box in a custom taxonomy page.

This is my code:

function lnw_quick_edit_custom_box($column_name, $screen, $name) {

if ( $screen !== 'edit-tags' ) return;

if ($column_name == 'special_star') {

?>
<fieldset>
    <div id="my-custom-content" class="inline-edit-col-special_star">
        <label>
            <span class="title"><?php _e('Special Star', 'my-theme'); ?></span>
            <span class="input-text-wrap">
            <select name="term_meta[special_star]" id="special_star_val">
            <option value="0">No</option>
            <option value="1">Sì</option>
            </select>
            </span>
        </label>
    </div>
</fieldset>
<script>
jQuery('a.editinline').on('click', function(){

    var now = jQuery(this).closest('tr').find('td.column-special_star').text();

    //console.log(now);

    if (now.charAt(0)=='S') {now_i = '1';};
    if (now.charAt(0)=='N') {now_i = '0';};

    //console.log(now_i);

    jQuery('#special_star_val').val( now_i );
});

add_action('quick_edit_custom_box', 'lnw_quick_edit_custom_box', 10, 3);

Code seems to work correctly because now and now_i variables are populated by correct values, but jQuery('#special_star_val').val( now_i ) don't select the right option of select field.

I don't understand why...

thanks a lot! Danilo

0

If you have multiple <a href="#" class="editinline">#</a> your jQuery should use on() to save memory. Add .editinline selector to attach the function (handler) to multiple elements (in this case — <body> children)

jQuery('body').on('click', '.editinline', function(){

    var now = jQuery(this).closest('tr').find('td.column-special_star').text();

    //console.log(now);

    if (now.charAt(0)=='S') {now_i = '1';};
    if (now.charAt(0)=='N') {now_i = '0';};look like this

    //console.log(now_i);

    jQuery('#special_star_val').val( now_i );
});

https://jsfiddle.net/47fd3fnu/

If you have single, you can use click() which is a shortcut to on('click', '...', '...'):

jQuery('.editinline').click(function(){
     ..........        
});

https://jsfiddle.net/47fd3fnu/2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.