How to include custom javascripts and stylesheets in your applicationUse the custom_javascripts and custom_stylesheets blocks to include your own custom javascript and CSS files in your application.
If you are not yet familiar with the concept of blocks and slots in Xataface, you may wish to refer to Changing the Look and Feel of Your Application for an introduction. It is not uncommon to want to include your own custom styles or javascripts in your web applications. Xataface includes 2 slots/blocks in its main template that are reserved for this purpose:
Whatever content you place in these slots will appear in the head section of the page. Theoretically you could include any content here, but the names suggest that you should include javascript and css files here. Adding a custom javascriptLet's begin by creating our javascript file as follows:
Using your javascripts in event handlersAbove we have made a javascript function named happyBirthday. Suppose we want this function to be called whenever the firstname field is changed in our people table edit form. To do this we need to attach an onchange event handler to the firstname field of our form. Note that we can apply any HTML attributes we want to our field using the widget:atts: directive in the fields.ini file as follows:
[firstname] This directive will cause our happyBirthday() function to be called with the value of the firstname field whenever its value is changed (i.e. when you change the field and tab out of it). If you load up your application, and go to the edit form for our table, and make a change to the firstname field, you will see our little javascript pop-up alert saying "Happy birthday". |