Dropdown to hide or display a form

chozma

Member
Hi all,

Could anyone help me figure out how to hide and display a form please? I want to have a dropdown that allows a user to select which form they want to see in a sidebar. I have figured out how to make a dropdown listen for changes but I am not sure what the code is to hide and display forms. Any ideas?

Much appreciated, thanks all,

Hannah
 
By 'sidebar' do you mean a Joomla module showing forms using the Fabrik Form Model?
The best way to control display of something like that would be to use a form javascript file. http://fabrikar.com/forums/index.php?wiki/form-javascript/#adding-javascript-to-a-form-header

If my assumption of what you want to do is correct, the easiest way I can think of doing this would be to assign a class name to each of those Joomla modules (e.g. if the form IDs are 10,11,12 - add ' form10', ' form11', and ' form12' as the Module Class Suffix in the Advanced configuration tab for each of the corresponding modules.) And use 'form10', 'form11', and 'form12' as the values in your dropdown. Then create a function in your form_#.js file that would take the class name of the module to be shown as its parameter and 1.hide all the modules/forms, 2.show the module/form that should be displayed.
Code:
function showForm(className) {
    jQuery("div[class*=form10],div[class*=form11],div[class*=form12]").hide();
    jQuery("div[class*=" + className +"]").show();
}
Then call that showForm function as both a javascript 'load' and 'change' event of the dropdown element (passing it the className/value of the selected option).
 
Thanks so much Bauer, that was exactly the kind of guidance I was hoping for. I did mean Joomla modules, or at least that seemed to an obvious way to display the forms, though I am not sure if that is computationally expensive (ie slow) way of doing it or not.

Its been many years since I have coded and am learning PHP and Javascript as I go... Anyway, I have got it all working now.

Thanks again for your help, much appreciated x
 
Well responses like that make my day too - no problem, glad I could help.:)

I was going to suggest - especially if you have more than just a few of these 'sidebar' forms - that you link those forms (the table containing those forms) directly to that parent table/form so they would all display as 'repeat groups'. (Repeat groups are for storing data in related database tables) That would at least render/paint them all much faster as it's done in one query rather than individual queries to create those modules. http://fabrikar.com/forums/index.php?wiki/groups/
You would still have to write some javascript to trigger the show/hide of the correct repeat group in the form based on the dropdown option selected.
 
Ok cool, I get the concept of what you're suggesting and yes that does sound much more efficient. I appreciate the suggestion, thanks. Selecting forms via a dropdown will be a key way of accessing functionality in the app I'm writing so I want it to be quick and slick! At the moment I'm just learning how to do different things in a test environment on my local server so am experimenting away and keen to explore this.

However, after playing around a bit I'm not confident I really understand how I do this in practice, ie link these forms to a parent form. I think I should be able to add groups to forms via the groups tab of the form. However, the list of possible groups is very short, its not showing all the groups that exist and I don't know the reason for that.I'm not even sure if this is what you had in mind?

I could spend a few more hours messing around and I'm sure I could get it to work but then I wouldn't understand what I'm doing and why its working or not. So I would appreciate a bit more guidance on this please when you have a mo :0)

Thanks, Hannah
 
Actually I don't know what I was thinking. I guess I wasn't really clear with what you wanted to do. But the repeat groups always contain identical forms/elements - just with different data - and it sounds like all of your forms are going to be different and you'd have to join multiple tables (one for each form). So I don't see how that would really be any faster and you're probably better off just doing it the way you were.

You could also use popups to show the forms rather than modules. That way the form isn't rendered until the user selects it and you don't have to write any javascript to hide the forms. That would probably be the best route - especially if those forms are pretty simple with just a handful of elements and your talking about more than just a few different forms. If you're lucky someone will jump into this thread who has a clearer head, and more experience doing something similar, than I do right now.:(
 
:D I'm kinda relieved you said that actually Bauer as I was thinking about it last night when doing dinner and started to think I had missed the point of a lot of the Fabrik functionality! Phew!

Yes, the pop-ups could work and I'll give that a go a bit later down the line if/when I need to think about performance optimisation. A lot of the design of the app is in my head at the moment and whilst I think the forms will be simple its not until you've actually coded it for real that you realise how much stuff you forgot about and how inappropriate your plans were!

Thanks again! Its nice that I have at least got something working the way I want, though I have broken it all with a crappy new template I am trying to write. The javascript doesn't seem to work anymore. I'm trying to see the funny side and keep telling myself that its all good that I am learning... :eek:

Hannah
x
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top