Get table name & form name from common code invoked by form_XX.js

TonyBenedetti

Hobbyist Programmer & Fabrik Fan
I've already learned from Hugh over in another thread how to load that common code. Thanks again, Hugh.

But I would like my form_XX.js files to be as "skinny" as possible so that I can use a crop of functions in a single "common.js" file. I have several similar forms (with the possibility of many more).

Each of the forms currently has, for example, a function to hide/show various combinations of tabbed groups based on a set of radio buttons.

I think that if I can pass "this" (i.e., the "calling" element) through the form_XX.js to the common.js, I would be able to manipulate all the necessary hiding & showing and value & label changing that I need to do. But I can't do that unless I know the table name and form name.

Of course, I know that I could hard code them in each of the form_XX.js files. But I would really like to avoid making changes to each of the form_XX.js files to accommodate any changes down the line to the common.js file.

Bottom line -- Does anyone out there in the FabComm know how to retrieve the table name and the form name from "this"? I've searched and searched the forums & wiki and I guess I'm just not insightful enough to have gleaned the answer.

Thanks for listening,
Tony
 
Last edited:
We don't specifically give the table name in the form object, but we do give the primary key name in both form and list object, so for example, if you are passing 'this' in to an element JS function ...

Code:
function doMyStuff(el) {
   // PK is in el.form.options.primaryKey, so you can regex out the table name ...
   var tableName = el.form.options.primaryKey.match(/(\w+)___\w+/)[1];
}

Not sure what you mean by the "form name" though.

-- hugh
 
If I had thought it through I would have realized that what I really needed is simply the "form number" and not "form name". Even my limited JS skills include the ability to concatenate 'form_' to 23 to come up with 'form_23'. I am such a dimwit! Given that -- is there a way to get that pesky number via the "this" parameter?

Second note -- how in heaven's name do keep all this stuff in your head? Keep it up and your skull is going to explode!

Thanks for the answer and even more thanks for your time.
Tony
 
A lot of the time I don't have it straight in my head, so I just go and look. For this, I just used the Chrome debug console and examined the form object on a test form. Found options.primaryKey (can't even remember why that's there, no idea what we use it for), went and did a global search for it in PHP Storm to make sure it's always set (which it is), tested that regex in the debugger to make sure that worked, and answered you.

That's why supporting Fabrik takes a lot of time and effort, and why we REALLY appreciate it when people pay for a sub. ;)

The form id is in el.form.id.

-- hugh
 
Thanks again, Hugh! You're my hero! You have given me extraordinary support even though I am just a "hobbyist programmer" who is developing a website that likely will have only one user -- me!

I encourage you to ignore my postings unless you think that answering will aid those folks who have paid for support or if you think that the answer will evolve into something that will make Fabrik even greater.

And a poke at you folks who are using Fabrik in commercial endeavors but hanging out here in the Community Forum. Please consider a subscription.

Thanks again Hugh !
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top