Skip Navigation

[Resolved] Adding Javascript to CRED Post Form

This support ticket is created 7 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Author
Posts
#406434

I am trying to: Use Javascript/JQuery with CRED Post Forms

I visited this URL: https://toolset.com/documentation/user-guides/adding-custom-javascript-views/

Hello there Toolset Support!

I would like to use some custom JQuery code. The code I am using is already working on a different site where I am not using Toolset. I think I just don't know the proper way how to use JQuery with Toolset.

This is exactly how I pasted the JQuery code into the Javascript Editor. What am I doing wrong?

<script>
(function($) {

$("#uploadtextfield").click(function() {
$('#fileuploadfield').click()
});

$("#uploadbrowsebutton").click(function() {
$('#fileuploadfield').click()
});

$('#fileuploadfield').change(function() {
$('#uploadtextfield').val($(this).val());
});

})(jQuery);
</script>

Thank you for your time and support.
Have a nice day.
Nicholas

#406542

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

You normally need to wait until the DOM is ready before your code runs.

Where you have the custom JS box try adding your code like so:

(function($) {
    $(document).ready(

        /* Bespoke code goes here */

        $("#uploadtextfield").click(function() {
            $('#fileuploadfield').click()
        });

        $("#uploadbrowsebutton").click(function() {
            $('#fileuploadfield').click()
        });

        $('#fileuploadfield').change(function() {
            $('#uploadtextfield').val($(this).val());
        });

    );
})(jQuery);

I haven't looked at what your code does, but it should be ready to work when added like so.

#407144

Thank you very much for your help Nigel.

I would just like to style the default file upload button, so this bit of code should replace the default file upload button.
Maybe you know a faster way how to do this?
Just let me know if you have time.

Have a good day.

Nicholas

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.