Development

Changeset 23647

You must first sign up to be able to contribute.

Changeset 23647

Show
Ignore:
Timestamp:
11/05/09 22:16:02 (4 years ago)
Author:
boutell
Message:

pkCheckboxEnables can now show/hide a selector, in addition to the usual selector that gets enabled/disabled.
This is great if some items to be "disabled" are not form elements or you want to just hide a row using
a jQuery "has" selector.

Ditto for pkSelectEnables.

JavaScript for a CRUD AJAX chunk form is now loaded at the end of the form so that jQuery code can affect things
created by jQuery code inside the form's template and/or widgets.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/pkToolkitPlugin/trunk/lib/helper/pkSubCrudHelper.php

    r23411 r23647  
    228228  ob_start(); 
    229229  include_stylesheets_for_form($form); 
    230   include_javascripts_for_form($form); 
    231230  echo $form; 
    232231?> 
     
    236235  </ul> 
    237236<?php 
     237  // Do this after the form so that we can do things like disabling stuff that 
     238  // gets created by JS in widgets  
     239  include_javascripts_for_form($form); 
    238240  return ob_get_clean(); 
    239241} 
  • plugins/pkToolkitPlugin/trunk/web/js/pkControls.js

    r23417 r23647  
    523523// when the checkbox is checked? Here's your answer 
    524524 
    525 function pkCheckboxEnables(boxSelector, itemsSelector) 
     525// The optional hideItemsSelector contains items that should be hidden rather than disabled. 
     526// You can pass undefined for itemsSelector if you are only interested in hiding items. This 
     527// combination is useful if you want to fully disable a datepicker with an input field 
     528// (disable-able) and a calendar icon (not disable-able, but hide-able). 
     529 
     530// Both selector arguments are optional. To skip itemsSelector, pass undefined (not null) 
     531// for that argument. 
     532 
     533function pkCheckboxEnables(boxSelector, itemsSelector, hideItemsSelector) 
    526534{ 
    527535  $(boxSelector).data('pkCheckboxEnablesItemsSelector', itemsSelector); 
     536  $(boxSelector).data('pkCheckboxEnablesHideItemsSelector', hideItemsSelector); 
    528537  $(boxSelector).click(function() { 
    529538    update(this); 
     
    533542  { 
    534543    var itemsSelector = $(checkbox).data('pkCheckboxEnablesItemsSelector'); 
     544    var hideItemsSelector = $(checkbox).data('pkCheckboxEnablesHideItemsSelector'); 
    535545    if ($(checkbox).attr('checked')) 
    536546    { 
    537       $(itemsSelector).removeAttr('disabled'); 
     547      if (itemsSelector !== undefined) 
     548      { 
     549        $(itemsSelector).removeAttr('disabled'); 
     550      } 
     551      if (hideItemsSelector !== undefined) 
     552      { 
     553        $(hideItemsSelector).show(); 
     554      } 
    538555    } 
    539556    else 
    540557    { 
    541       $(itemsSelector).attr('disabled', 'disabled'); 
     558      if (itemsSelector !== undefined) 
     559      { 
     560        $(itemsSelector).attr('disabled', 'disabled'); 
     561      } 
     562      if (hideItemsSelector !== undefined) 
     563      { 
     564        $(hideItemsSelector).hide(); 
     565      } 
    542566    }  
    543567  } 
    544   $(boxSelector).each(function() { update(this) }); 
     568  // At DOMready so we can affect controls created by js widgets in the form 
     569  $(function() { 
     570    $(boxSelector).each(function() { update(this) }); 
     571  }); 
    545572} 
    546573 
     
    551578// when "Other" is chosen from an "Institution Type" menu. 
    552579 
    553 function pkSelectEnables(selectSelector, itemsSelectors) 
     580// If desired a second hash of option values pointing to item selectors that 
     581// should be shown/hidden rather than enabled/disabled can also be passed. 
     582 
     583// Both selector arguments are optional. To skip itemsSelectors, pass undefined (not null) 
     584// for that argument. 
     585 
     586function pkSelectEnables(selectSelector, itemsSelectors, hideItemsSelectors) 
    554587{ 
    555588  $(selectSelector).data('pkSelectEnablesItemsSelectors', itemsSelectors); 
     589  $(selectSelector).data('pkSelectEnablesHideItemsSelectors', hideItemsSelectors); 
    556590  $(selectSelector).change(function() { 
    557591    update(this); 
     
    561595  { 
    562596    var itemsSelectors = $(select).data('pkSelectEnablesItemsSelectors'); 
    563     for (var option in itemsSelectors) 
     597    var hideItemsSelectors = $(select).data('pkSelectEnablesHideItemsSelectors'); 
     598    if (itemsSelectors !== undefined) 
    564599    { 
    565       $(itemsSelectors[option]).attr('disabled', 'disabled'); 
     600      for (var option in itemsSelectors) 
     601      { 
     602        $(itemsSelectors[option]).attr('disabled', 'disabled'); 
     603      } 
     604      var option = select.value; 
     605      if (itemsSelectors[option]) 
     606      { 
     607        $(itemsSelectors[option]).removeAttr('disabled'); 
     608      } 
    566609    } 
    567     var option = select.value; 
    568     if (itemsSelectors[option]) 
     610    if (hideItemsSelectors !== undefined) 
    569611    { 
    570       $(itemsSelectors[option]).removeAttr('disabled'); 
     612      for (var option in hideItemsSelectors) 
     613      { 
     614        $(hideItemsSelectors[option]).hide(); 
     615      } 
     616      var option = select.value; 
     617      if (hideItemsSelectors[option]) 
     618      { 
     619        $(hideItemsSelectors[option]).show(); 
     620      } 
    571621    } 
    572622  } 
    573   $(selectSelector).each(function() { update(this) }); 
     623  $(function() { 
     624    $(selectSelector).each(function() { update(this) }); 
     625  }); 
    574626} 
    575627