1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Hide and unhide a field based on another field doesn't work

Discussion in 'Community' started by tanya2015, Oct 12, 2019.

  1. tanya2015

    tanya2015 Member

    Level: Community
    Hello,
    I'm trying to use code like
    Code (Text):

    var $btnObj = Fabrik.getBlock('form_XXX').elements.get('yourTableName___yourButtonFieldName');

    if (this.getValue() != '0')
    {
      $btnObj.show();
    }
    else
    {
      $btnObj.hide();
    }
    from
    http://fabrikar.com/forums/index.ph...eld-based-on-another-field.50215/#post-262499

    and with hide everything is ok, but with show does't work although I take element.js (2 files) from git.
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Firstly, you should never "cherry pick" files from GitHub. Always do a full update. This is because changes in one file in git may well depend on changes in other files, and you can wind up with very subtle, nasty bugs if you have mismatching files.

    As for the actual issue ... did you reload JS in your browser? Easiest way is to open dev tools (ctrl-shift-i) in Chrome, then right click on the normal reload button in the brower, and "Empty cache and hard reload".

    -- hugh
     
  3. tanya2015

    tanya2015 Member

    Level: Community
    Thank you Hugh,
    I had the latest version of fabrik and plugin installed before, so first I thought that as I have last version everything should work. Now I don't know should I install again fabrik 3.9 to cancel changes I make getting files from git.
     
  4. tanya2015

    tanya2015 Member

    Level: Community
    Ok, I change files, took them from 3.9 fabrik as I installed it 3 weeks ago,
    I did eveything you recommend and still have no results.
    I try to use
    Code (Text):
    var $fiohiddenObj = Fabrik.getBlock('form_1').elements.get('vks___fiohidden');
    var $fiohiddenElem = $fiohiddenObj.getElement();
    var $fiohiddenElemContainer = $fiohiddenElem.findClassUp('fabrikElementContainer');
    $org = this.getValue();
    if ($org == '39')
    {$orgfioObj.hide();
    $fioObj.hide();
    $fiohiddenElemContainer.classList.remove('fabrikHide');
      $fiohiddenElemContainer.show();
      }
    it's not results I expected, with hide it's ok, but with show


    I inspected code in case if this element not hidden this must look as below

    Code (Text):
    <div class="control-group fabrikElementContainer plg-field fb_el_vks___fiohidden  fabrikDataEmpty  span12">

            <label for="vks___fiohidden" class="fabrikLabel control-label"> Name </label>
     
    <div class="controls">
     
        <div class="fabrikElement">
         
    <input type="text" id="vks___fiohidden" name="vks___fiohidden" size="10" maxlength="255" class="input-medium form-control fabrikinput inputbox text" value="">
        </div>

        <div class="fabrikErrorMessage">
                </div>

    if I use code to show $fiohiddenElemContainer.show();
    Code (Text):
    <div class="control-group fabrikElementContainer plg-field fb_el_vks___fiohidden" style="display: block;">
        Name
    <div class="controls">
     
        <div class="fabrikElement">
         
    <input type="hidden" id="vks___fiohidden" name="vks___fiohidden" class="input-medium form-control  hidden fabrikinput inputbox text" value="">
        </div>

        <div class="fabrikErrorMessage">
                </div>
    </div>
    and I didn't get input field, and no label....it's not look like as in case this element ssign not hidden in form view.
    Appreciate any comment. In case I use code like i wrote in the start message i did't show anyting.

    joomla version 3.9.12, fabrik version 3.9
     
  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Your code doesn't make much sense, as orgfioObj and fioObj don't seem to exist, they aren't set up in the code.

    And I'm not sure why you are manually finding the container. The following should work ...

    Code (Text):

    var fiohiddenObj = Fabrik.getBlock('form_1').elements.get('vks___fiohidden');
    // you can now hide or show it with ...
    fiohiddenObj.hide();
    // ... or ...
    fiohiddenObj.show();
     
    The hide() and show() methods for the Fabrik element object already hide/show the container ...

    https://github.com/Fabrik/fabrik/blob/master/media/com_fabrik/js/element.js#L903

    ... and as you can see, that original bug with the class being wrong ('.fabrikHide') has been fixed.

    -- hugh
     
  6. tanya2015

    tanya2015 Member

    Level: Community
    Thank you Hugh, I understand my mistake. because I download version from site not from git now I update from git and everything is ok.
     
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community

Share This Page