Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add documentation for JS admin backend code #516

Open
sknopp opened this issue May 16, 2020 · 0 comments
Open

add documentation for JS admin backend code #516

sknopp opened this issue May 16, 2020 · 0 comments

Comments

@sknopp
Copy link

sknopp commented May 16, 2020

Hi!

Issue Overview

I've nearly finished developing some basic ticket booking elements for torro-forms. But i can't figure out how to correctly include my JS code so it is executed AFTER the form elements have been loaded. Currently i'm helping myself by just using setTimeout() 😞

Current Behavior

So my JS code is included in the extension.php as shown by example code.:

class Extension extends Extension_Base {
        // [...]
	protected function register_assets() {
                // [...]
		$this->assets->register_script( 'admin-ticketselection-element', 'assets/js/admin-ticketselection-element.js', array(
			'deps'			=> array( 'jquery', 'torro-template-tag-fields', 'torro-admin-form-builder' ),
			'ver'			=> $this->version,
			'in_footer'		=> true,
			'localize_name' => '',
			'localize_data' => array(

			)
		));
                // [...]
         }
        // [...]
}

The admin-ticketselection-element.js looks as follows:

( function( torro, $ ) {
	'use strict';
    $(document).ready(function(){
		setTimeout(function(){
	        $(".plugin-lib-ticketchoices-control").each(function(index){
	            let self = $(this);
	            $(this).find("option").each(function(option_index){
	                if($(this).attr('value') == self.data("value")){
	                    $(this).attr('selected', '');
	                }
	            });
	        });
		}, 2000); //yepp, hacked! But only god knows how to get this code executed at the right time!
    });
}( window.torro, window.jQuery ) );  // <-- HOW DO I USE THOSE CORRECTLY?!

Possible Solution

Please document what to do to get the code running at the right time after the page has loaded.

Screenshots / Video

This is, how it looks at the moment. The values for the dropdown fields should be set by JS above:
Bildschirmfoto 2020-05-16 um 14 56 26

Thank you for any helpful hint! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant