-
Posts
926 -
Joined
-
Last visited
-
Days Won
1
Everything posted by PWaddict
-
@kixe I've updated the module to 2.1.1 and now I can't even save the page. I'm getting the following error: Method SelectableOptionArray::getLanguageValue does not exist or is not callable in this context
- 100 replies
-
- 1
-
- template
- autogenerate
-
(and 2 more)
Tagged with:
-
Blank & 0 are equivalent in inputfield dependencies
PWaddict replied to PWaddict's topic in General Support
Already tried that and it doesn't even getting required at all. -
I would like a field to be required only if a float field has 0 value (not blank). So, adding this: my_float_field=0 on "Required only if" section it makes the field required when it has 0 value and when it's empty too. Is it possible to get the field required ONLY when it has 0 value?
-
@blynx Unfortunately the showinfo parameter doesn't work anymore since it's deprecated. You should remove it from the module.
-
I had it there since the beginning where I was actually only validating the title (see first post). So removing title!='' and adding include=all does the job.
-
It seems that the problem is caused by the selector: title!='' cause the title on alternate languages is actually empty. EDIT: Removing title!='' and adding include=all now getting the proper json on all languages.
-
@kongondo Validating coupons while browsing the site on alternate languages always return "Discount code not found" because the json on those languages is empty. Only on the default language the json is returned properly. Why is this happening???
-
and here is the final code for the php template for the hidden page that will get all the available coupons ONLY via ajax: <?php namespace ProcessWire; $couponsArray = array(); $couponsJSON = ''; $coupons = $pages->find("template=paddiscount, title!='', pad_percentage!=''"); if($coupons->count) { foreach($coupons as $coupon) { $couponValidUntil = $coupon->pad_valid_until ? date("Y-m-d", $coupon->pad_valid_until) : ''; $couponsArray[$coupon->title] = $couponValidUntil; } header('Content-Type: application/json'); $couponsJSON = json_encode($couponsArray); } if($config->ajax) { echo $couponsJSON; } ?> If I did something wrong please let me know.
-
I think I figured it out. I had to set the template with the hidden coupons page to json header and then modify the js code like this: $.get('../my-hidden-coupons-page/', function (data) { var coupons = data; if (discount != '' && (!coupons.hasOwnProperty(discount))) { alert('Discount not found'); } else if (discount != '' && coupons[discount] != '' && coupons[discount] <= today) { alert('Discount expired'); } });
-
@kongondo The coupons are actually exposed in my checkout page source. So I created a new hidden page with a different template and added there only your code to avoid exposing them but now I'm not sure how to proceed. <?php namespace ProcessWire; $couponsArray = array(); $couponsJSON = ''; $coupons = $pages->find("template=paddiscount, title!='', pad_percentage!=''"); if($coupons->count) { foreach($coupons as $coupon) { $couponValidUntil = $coupon->pad_valid_until ? date("Y-m-d", $coupon->pad_valid_until) : ''; $couponsArray[$coupon->title] = $couponValidUntil; } $couponsJSON = json_encode($couponsArray); } ?> <?php if($coupons->count) { ?> <script type="text/javascript">var coupons = <?= $couponsJSON ?>;</script> <?php } else { ?> <script type="text/javascript">var coupons = '';</script> <?php } ?> On checkout page I'm getting the error: "coupons is not defined" on console which is obvious cause this is a different page.
-
I'm doing the client side validation cause I have ajaxified the checkout form.
-
@kongondo I will try it with your code. Thanks. Isn't the server-side checking done by Padloper? If you go to PadOrderProcess.php on the line 95 there is a piece of code for checking the checkout form for invalid and expired coupons.
-
Ok I found how to do it: On php template: <script type="text/javascript">var coupons = <?php $coupons = $pages->find("template=paddiscount, title!='', pad_percentage!=''"); echo "{"; foreach($coupons as $coupon) { if ($coupon->pad_valid_until) { echo " '" . $coupon->title . "' : " . "'" . date("Y-m-d", $coupon->pad_valid_until) . "'" . ","; } else { echo " '" . $coupon->title . "' : " . "'" . "" . "'" . ","; } } echo "};"; ?></script> Outputs something like this: <script type="text/javascript">var coupons = { 'CODE1' : '', 'CODE2' : '2018-09-30',};</script> And the related code on main.js: var discount = $form.find('input[name=pad_discount_code]').val(); var today = new Date(); var dd = today.getDate(); var mm = today.getMonth() + 1; var yyyy = today.getFullYear(); if (dd < 10) { dd = '0' + dd; } if (mm < 10) { mm = '0' + mm; } today = yyyy + '-' + mm + '-' + dd; if (discount != '' && (!coupons.hasOwnProperty(discount))) { alert('Discount code not found'); } else if (discount != '' && coupons[discount] != '' && coupons[discount] <= today) { alert('Discount code expired'); }
-
I'm currently using this on my php template which outputs this: <script type="text/javascript">var coupons = ['CODE1','CODE2',];</script> <script type="text/javascript">var coupons = <?php $coupons = $pages->find("template=paddiscount, title!='', pad_percentage!=''"); echo "["; foreach($coupons as $coupon) { echo "'" . $coupon->title . "',"; } echo "];"; ?></script> and the related code on my main.js is this: var discount = $form.find('input[name=pad_discount_code]').val(); if (discount != '' && $.inArray(discount, coupons) == -1) { alert('Discount code not found'); } The above is working properly but now on the php template I need to add in the array also a timestamp value ($coupon->pad_valid_until) and on main.js I need to also check if there is timestamp associated with the coupon entered and if that timestamp is less than today then alert('Discount code expired'); I don't have much experience with this stuff and I don't know how to proceed. Can you please help me?
-
Module: Video embed for YouTube/Vimeo (TextformatterVideoEmbed)
PWaddict replied to ryan's topic in Modules/Plugins
I just converted a Textarea field to Textarea (Multi-language) and the module is working properly for every language. -
This actually works. I forgot earlier to modify the url. So it seems the problem is caused from the way I ajaxified the site. Anyway, thanks for the help.
-
I still can't see the AJAX bar. Maybe the problem is caused by localhost?
-
I haven't changed anything on module settings and yes it's enabled since I already can see the normal bar.
-
I'm using JQuery and on frontend I can see the header X-Requested-With: XMLHttpRequest but there is no AJAX bar. On backend there is no X-Requested-With: XMLHttpRequest header but I can see the AJAX bar.
-
Ah yes only on backend I can see the AJAX one. On frontend I can't see it even though the entire site is based on AJAX.
-
There are more than 1 bars??? How can I view the AJAX one?
-
@adrian Is it possible to view the values submitted on an ajax form and how?
-
I'm still using the 3.0.110. I've read about the changes on page names on 3.0.111 and that's why I asked if it affects the module.
-
@adrian Does the PW 3.0.111 affects the module?