Adam Posted May 22, 2024 Share Posted May 22, 2024 (edited) Hi I have a script that will ultimately be used to extend the functionality of one of the modules. It is used to count the values of all inputs and then, if too large a number is entered, correct the value on the front. Here's what it looks like. <input min="0" name="cat1" step="1" type="number" max="50" value="0" /> <input min="0" name="cat2" step="1" type="number" max="50" value="0" /> <input min="0" name="cat3" step="1" type="number" max="50" value="0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> <script type="text/javascript"> var max = 50; var $inputs = $('input'); function sumInputs($inputs) { var sum = 0; $inputs.each(function() { sum += parseInt($(this).val(), 0); }); return sum; } $inputs.on('input', function(e) { var $this = $(this); var sum = sumInputs($inputs.not(function(i, el) { return el === e.target; })); var value = parseInt($this.val(), 10) || 0; if(sum + value > max) $this.val(max - sum); }); </script> It works fine in html, but not in the store. To make things easier, I added the code to one of the tpl files to make it easier - removing the original content first. The browser shows it as in HTML - the function refers to the inputs, but in the front-end store it does not correct the values (screens). Request for help. Thanks in advance. Edited May 22, 2024 by Adam (see edit history) Link to comment Share on other sites More sharing options...
bera_ramazan Posted May 22, 2024 Share Posted May 22, 2024 please add this script to footer.tpl Link to comment Share on other sites More sharing options...
Adam Posted May 22, 2024 Author Share Posted May 22, 2024 Hi Bera Thank you. Maybe I'm doing something wrong, but it's still the same. This is what it looks like in footer.tpl. I forgot to add - it's Presta 1.6. Link to comment Share on other sites More sharing options...
bera_ramazan Posted May 23, 2024 Share Posted May 23, 2024 There is already a jquery library in Prestashop, you do not need to add it. Link to comment Share on other sites More sharing options...
Adam Posted May 23, 2024 Author Share Posted May 23, 2024 It just didn't work without adding it, so I added it here to be sure What is going on here? Link to comment Share on other sites More sharing options...
ps8modules Posted May 23, 2024 Share Posted May 23, 2024 Hi. Don't put *.js in tpl but in your module or in ./themes/your_theme/assets/js/custom.js 1 Link to comment Share on other sites More sharing options...
Adam Posted May 23, 2024 Author Share Posted May 23, 2024 Hi Thanks, this is how it will be done in the end. Now I'm trying everything in the tpl file because it didn't work in *.js either Interesting fact, it is not known yet what it is. Link to comment Share on other sites More sharing options...
ps8modules Posted May 23, 2024 Share Posted May 23, 2024 (edited) module hook: public function hookHeader() { if ($this->context->controller->php_self == 'product') { // identify page name $this->context->controller->addJS($this->_path.'views/css/script.js'); // your module javascript } } Sometimes it's better to show the page so a person can check it. It is not always possible to solve everything according to the picture. I'll give you a picture of the car and leave the front hood closed and ask you to tell me where my engine oil is leaking 😄 Edited May 23, 2024 by ps8modules.com (see edit history) Link to comment Share on other sites More sharing options...
Adam Posted May 23, 2024 Author Share Posted May 23, 2024 1 hour ago, ps8modules.com said: I'll give you a picture of the car and leave the front hood closed and ask you to tell me where my engine oil is leaking 😄 I know - your engine is leaking . But I know what it's about. Here is our live example - https://internetprojects.com.pl/getprice/pl/ See, you are smarter Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now