Hide Dynamically

Developers
2010-06-23
2013-04-25
  • Mike Metcalfe

    Mike Metcalfe - 2010-06-23

    Hi,

    I have a form that requires physical address fields, and field to indicate if the postal is the same as the physical, and the postal address fields. I created a hide-when-postal-equals-physical that I use to hide the postal fields if appropriate which works on the document. Is there a way to dynamically hide/show fields on the edit form?

    Mike

     
  • Jean Jordaan

    Jean Jordaan - 2010-06-23

    AFAIK Plomino doesn't support this .. you'd have to wire something like jQuery yourself.

     
  • Eric Brehault

    Eric Brehault - 2010-06-23

    Hello,

    As Jean said, dynamic hiding is not part of Plomino features, but you can create a Computed for display Richtext field that will contain a <script> tag and the needed javascript to achieve that

    Eric

     
  • Mike Metcalfe

    Mike Metcalfe - 2010-06-23

    Thanx for responding, guys. I can find a tutorial on the web and work out how to implement the jquery option but I'm not sure where to begin with Eric's proposal. Any samples around?

     
  • Jean Jordaan

    Jean Jordaan - 2010-06-23

    It's plain Javascript, so any generic tutorial should do.

     
  • Eric Brehault

    Eric Brehault - 2010-06-23

    in your form, create a new field, choose type=Rich text (so HTML is rendered), and mode=Computed for display (so the value is not stored because it is useless)
    and enter a formula like that:
    html="""
    <script>
    alter("This is javascript");
    el = jq('your-selector');
    el.hide();
    </script>
    """
    return html

    Eric

     
  • Mike Metcalfe

    Mike Metcalfe - 2010-07-29

    Hi Eric,

    Thanx for your advice. I have the postalAddress working correctly (hide or show) depending on the postalEqualPhysical selection by having the following code on the postalEqualPhsical field formula:

    html="""<script>
    $(document).ready(function() {
    $('#postalEqualPhysical').change(function() {
      var isEqualValue = $('#postalEqualPhysical').val();
      var address = $('#postalAddress');
      if (isEqualValue == 'Yes') {
       address.hide();
      } else {
       address.show();
      };
    });
    });
    </script>
    <select id="postalEqualPhysical"><option>No</option><option>Yes</option></select>
    """
    return html

    I  tried adding a jq load function to set the postalEqualPhysical (to either default 'No' or using the value of the field when viewing an existing document) - but I can't get it to work. I need this value set and I need the postalAddress to appear or not depending on this value.  Any ideas?

     
  • Eric Brehault

    Eric Brehault - 2010-07-29

    Hello,

    can you tell me what is your javascript error ?

    note: for your information, the dynamic hiden-when feature is part of the next plomino release, it is developped but it is not published yet
    we will publish it next week I think

     
  • Mike Metcalfe

    Mike Metcalfe - 2010-07-30

    Hi Eric,

    I found out that I should leave existing field (postEqualPhysical) as is (a selection field) and add a new computed new field with this formula:
    html = """<script>
    $(document).ready(function() {
      alert('ready: ' + $('#postalEqualPhysical').length);
      var thefield = $('#postalEqualPhysical');
      var isEqualValue = $('#postalEqualPhysical').val();
      var address = $('#postalAddress');
      if (isEqualValue == 'Yes') {
       address.hide();
      } else {
       address.show();
      };
    $('#postalEqualPhysical').change(function() {
    alert('Change');
      var isEqualValue = $('#postalEqualPhysical').val();
      var address = $('#postalAddress');
      if (isEqualValue == 'Yes') {
       address.hide();
      } else {
       address.show();
      };
    });
    });
    </script>
    <input type='hidden' name='postalEqualPhysicalComputed' />"""
    return html

    Now I get "ready: 0" alert on loading the page and I never get the "Change" alert when I change the selection on postalEqualPhysical.

     
  • Mike Metcalfe

    Mike Metcalfe - 2010-08-01

    I found bug - I got the selectors wrong. Sorry, jquery is new to me.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks