Guillaume Posted May 22, 2021 Share Posted May 22, 2021 Hi, In a module I am developping, for the admin page, I want to allow or disallow Payment by Installments. If allowed, then I want to allow the admin to select other fields (such as, minimum amount for installments, amount of the first installment, etc.) as below: My tpl file looks like this: My problem is that, the if condition seems to check what is actually in the database. And simply clicking on the field doesn't fill it in the database: for the detailed fields to appear (or disappear) one needs to tick in (or off) the option "Payment by Installments" and then save. And this is a bit cumbersome. What I am after, is a way to do display/hide fields upon click or selection (I have another similar issue, where I'd like a field to be displayed upon selection of a given value from a drop-down list) on another field. I believe this requires a bit of javascript, if anyone had an example or could point me out to another Cubecart module having this somewhere, that would be very helpful. Best regards, Guillaume index.tpl Link to comment Share on other sites More sharing options...
bsmither Posted May 22, 2021 Share Posted May 22, 2021 The All-in-One-Shipping module has two examples: Advanced Options on the first tab and choosing the scope of a zone. Also, the Foundation skin, at "checkout confirm" for not logged in visitors, has a checkbox that exposes or hides a password field (create an account), and has a checkbox that exposes or hides delivery address fields (deliver to billing address). Link to comment Share on other sites More sharing options...
Guillaume Posted May 23, 2021 Author Share Posted May 23, 2021 Thanks, I just realized it's a standard PHP/JS thing and there is nothing specific to TPL files. Still I believe there is something I am doing wrong: I have the "multipay" checkbox (line 100), which onclick is supposed to call a JS function (lines 102 through 115) to show/hide the div section multipay_details (hidden by default, line 123 onwards) But onclick nothing happens. I have tried to change the JS function to simple "alert" (commented lines 116 through 121), and when not commented it displays the alert indeed, so I believe I am doing something wrong in my JS function index.tpl Link to comment Share on other sites More sharing options...
Guillaume Posted May 23, 2021 Author Share Posted May 23, 2021 I've eventually managed to get things more or less working. Indeed, upon click on that checkbox, the fields show if they were hidden, and vice-versa. Now I'm trying to improve this by checking the actual value (is the box ticked or not?), as I believe it would be more reliable. I have tried the below, but for some reason, "document.getElementById(multipay)" always equals "null" and I am never able to retrieve its value... Is there anything I am doing wrong here? I would really like to make it value-based, because this would also solve my other use-case (below picture), where the admin chooses the payment system they want but there an option "other" where I'm dynamically displaying a field where the admin would input their custom value: Best regards, Guillaume Link to comment Share on other sites More sharing options...
bsmither Posted May 23, 2021 Share Posted May 23, 2021 Assuming there is an element with id='multipay', perhaps the argument in this case must be a quoted string, as opposed to an unquoted variable or constant. Link to comment Share on other sites More sharing options...
Guillaume Posted May 23, 2021 Author Share Posted May 23, 2021 You're right - apologies this was very stupid of me. I've actually just realized that this is actually a basic PHP/JS matter... From what I have read online, apparently for a checkbox I can get its status via the attribute "checked" (although I am not sure whether the attribute "checked" represents the default status of the checkbox, or its actual status at the time javascript/php is executed). I have therefore tried the below (where multipay is the checkbox, and multipay_details is the section to be displayed if checkbox is checked). In the javascript function multipay is therefore the fromId and I am trying to base the action depending on its attribute "checked". Unfortunately, with either of the methods I use to get it (chk and chk2), it is always "true" (whether the box is ticked or unticked). Any obvious reason for that? index.tpl Ok I'm gonna answer this one myself, I managed to make the below code work: Thanks a lot for your help! index.tpl Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.