如何解决自定义字段或者小工具里图片上传后update不更新

Published
2023-08-05
浏览次数 :  54

需要手动给图片地址的那个input添加一个触发:

$('#widget-tr_qrcode_widget-4-image_url').trigger('change');

完整的js:

  jQuery(document).ready(($) => {
    console.log('oolooo');
    $('#widgets-editor').on('click', '.custom_image_widget_upload_button', function (e) {
        e.preventDefault();
        
        var button = $(this),
            custom_uploader = wp.media({
                title: 'Choose Image',
                library: {
                    type: 'image'
                },
                button: {
                    text: 'Select Image'
                },
                multiple: false
            }).on('select', function () {
                var attachment = custom_uploader.state().get('selection').first().toJSON();
                $('#widget-tr_qrcode_widget-4-image_url').val(attachment.url);

                $('#widget-tr_qrcode_widget-4-image_url').trigger('change');


            }).open();
    });

    

});

  • 标签1
  • 标签1
  • 标签1
Top