| | 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 | } |
|---|