Development

Changeset 3537

You must first sign up to be able to contribute.

Changeset 3537

Show
Ignore:
Timestamp:
02/23/07 00:45:19 (6 years ago)
Author:
davedash
Message:

added function yui_live_input_tag($name, $default = null, $options = array())

This is just like input_tag, except an option of url and update can be specified to update a specific element in your DOM with a specific value.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfYUIPlugin/lib/helper/YUIConnectionHelper.php

    r3481 r3537  
    1616 * @author     Pierre Minnieur <pm@pierre-minnieur.de> 
    1717 * @author     Nick Winfield <enquiries@superhaggis.com> 
     18 * @author     Dave Dash <dave (dot) dash /at/ spindrop . us> 
    1819 * @version    SVN: $Id$ 
    1920 */ 
     
    233234    return form_tag($submit_route, $options); 
    234235  } 
     236   
     237  /** 
     238   * Returns a text input tag that makes an ajax request onchange that  
     239   *  updates a specified element 
     240   * 
     241   * Example usage: 
     242   *    
     243   *   <div id="results"></div> 
     244   *   <?php echo yui_live_input_tag('@form_submit', array( 
     245   *     'url' => '@live_form', 
     246   *     'update' => 'results' 
     247   *   )) ?> 
     248   * 
     249   *  @form_submit does the final submission 
     250   *  @live_form takes a dynamic submission and  
     251   * 
     252   * This is useful for live javascript validation. 
     253   * 
     254   * @param string $name 
     255   * @param string $default 
     256   * @param array $options 
     257   * @see input_tag 
     258   */ 
     259 
     260    function yui_live_input_tag($name, $default = null, $options = array()) 
     261    { 
     262 
     263      sfYUI::addComponent('yahoo'); 
     264      sfYUI::addComponent('connection'); 
     265      $options = _parse_attributes($options); 
     266 
     267      $url = ''; 
     268      if (isset($options['url'])) 
     269      { 
     270        $url = url_for($options['url']); 
     271        unset($options['url']); 
     272      } 
     273      $update = ''; 
     274      if (isset($options['update'])) 
     275      { 
     276        $update = $options['update']; 
     277        unset($options['update']); 
     278      } 
     279 
     280      $func = 'new function(){c=YAHOO.util.Connect;'; 
     281      $func .= 'c.initHeader(\'X-Requested-With\', \'XMLHttpRequest\');'; 
     282      $func .= 'c.asyncRequest("POST", "'.$url.'",{success:function(o){document.getElementById("'.$update.'").innerHTML=o.responseText;}},"value="+event.target.value);}'; 
     283      $options['onchange'] = $func; 
     284      return input_tag($name, $default, $options); 
     285    }