News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Adding a symbol after a custom field

Started by Malex, September 08, 2016, 11:28:56 AM

Previous topic - Next topic

GJC Web Design

should be at the bottom with the rest of the js

does it load?
can u see it?
is there console errors?
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Malex

#31
I can see it, no error

I tried :

- At the very end of productdetail, before last </div>
Not loaded

- before or after

$j = "Virtuemart.container = jQuery('.productdetails-view');
Virtuemart.containerSelector = '.productdetails-view';";
vmJsApi::addJScript('ajaxContent',$j);

Loaded, not working

- in cutomfield.php after
if ($productCustom->field_type == "E") {
not loaded

- at the end of cutomfield.php
Loaded, not working

Is there a possibility that


$(window).load(function()
{
(function($)
{

is a wrong syntax for VM ?

Here is the last actual code i'm using in productdetail :

http://demo.magarantie.com/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=1&Itemid=357

$euro = '$(window).load(function()
{
(function($)
{
  $.fn.setCursorPosition = function(pos) {
    if ($(this).get(0).setSelectionRange) {
      $(this).get(0).setSelectionRange(pos, pos);
    } else if ($(this).get(0).createTextRange) {
      var range = $(this).get(0).createTextRange();
      range.collapse(true);
      range.moveEnd("character", pos);
      range.moveStart("character", pos);
      range.select();
    }
  }
}
(jQuery));

    $("#mycustomid_31 input").keyup(function()
{
        if ($(this).val().split("").pop() !== \'€\') {
            $(this).val($(this).val() + " €");
            $(this).setCursorPosition( $(this).val().length - 2)
        }
    });
});';
vmJsApi::addJScript('euro',$euro);



Malex

#32
 :-[
So sorry, finally i've found an error

Uncaught TypeError: $(...).load is not a function
But this function works in original code ..
:o


Malex

YESSSSSSSSSS !!!

By the end, i found :
Just had to replace
euro = '$(window).load(function()
by
$euro = 'jQuery(document).ready(function($)

Many, many thanks again for you patience !!!!!!!!


Malex

Quote from: GJC Web Design on September 13, 2016, 12:36:21 PM

as explained in the vmjsapi instructions how can u load a js from the head if your refreshing the page content by ajax?


Finally, it's possible to load js from the head ...regardless your refreshing the page content by ajax;
No need to use php code, i think it could be useful with lot of product to modify the
"   $("#mycustomid_X input").keyup(function(){" line but, in my case, here is the solution :
because i have only 7 products whith this needed field,
in defaut.php productdetail page, after


$j = "Virtuemart.container = jQuery('.productdetails-view');
Virtuemart.containerSelector = '.productdetails-view';";
vmJsApi::addJScript('ajaxContent',$j);

I putted :

if  ($this->product->virtuemart_product_id == 1) {
vmJsApi::addJScript('euro1');
}
if  ($this->product->virtuemart_product_id == 2) {
vmJsApi::addJScript('euro2');
}
if  ($this->product->virtuemart_product_id == 3) {
vmJsApi::addJScript('euro3');
}
...

and here is the euro1.js file located in templates/mytemplate/js :

jQuery(document).ready(function($)
{
(function($) {
  $.fn.setCursorPosition = function(pos) {
    if ($(this).get(0).setSelectionRange) {
      $(this).get(0).setSelectionRange(pos, pos);
    } else if ($(this).get(0).createTextRange) {
      var range = $(this).get(0).createTextRange();
      range.collapse(true);
      range.moveEnd('character', pos);
      range.moveStart('character', pos);
      range.select();
    }
  }
}(jQuery));

   $("#mycustomid_X input").keyup(function(){
        if ($(this).val().split('').pop() !== '€') {
            $(this).val($(this).val() + " €");
            $(this).setCursorPosition( $(this).val().length - 2)
        }
    });
});

where #mycustomid_X is the ID obtained by modifing customfields.php

if (!empty($field->display)){
?><div class="product-field-display" id="mycustomid_<?php echo $field->virtuemart_customfield_id?>"><?php echo $field->display ?></div><?php
}


Again and again thank's a lot for your precious help !!!

GJC Web Design

Well done..

but your not in the above loading from the joomla system "in the head" (which is the problem with ajax) 

your using the vmjsapi  which as in the docs can load any resource within the page
It doesn't really matter where the resource is
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Malex


rosietesmen

Custom fields can be used to store additional contact information such as a subscriber's address, city, country, or phone number. They're also great for collecting unique information about subscribers to help you plan more relevant and personalized email content.