0) $results.=', '; $v=Key($items); $results.='{ "v": '.$form->EncodeJavascriptString($v).', "e": '.$form->EncodeJavascriptString($form->EncodeJavascriptString(HtmlSpecialChars($v))).', "d": '.$form->EncodeJavascriptString($items[$v]).' }'; } return($results.']'); } Function GetCompleteValues(&$form, $arguments) { if(!IsSet($arguments['CompleteValues']) || GetType($complete_values=$arguments['CompleteValues'])!='array' || count($complete_values)==0) return('it were not specified valid complete values'); $this->complete_values=$complete_values; return(''); } Function SearchCompleteValues(&$form, $text, &$found) { if(strlen($text)==0) $found=$this->complete_values; else { $t=strtolower($text); for($found=array(), Reset($this->complete_values), $v=0; $vcomplete_values); $v++, Next($this->complete_values)) { $c=Key($this->complete_values); if(!strcmp($t, strtolower(substr($c, 0, strlen($t))))) $found[$c]=$this->complete_values[$c]; } } return(''); } Function AddInput(&$form, $arguments) { if(!IsSet($arguments['CompleteInput']) || strlen($arguments['CompleteInput'])==0) return('it was not specified a valid text input to complete'); $this->text=$arguments['CompleteInput']; if(IsSet($arguments['CompleteMinimumLength'])) { $minimum_complete=intval($arguments['CompleteMinimumLength']); if($minimum_complete<=0) return('it was not specified a valid minimum length to complete the text'); $this->minimum_complete=$minimum_complete; } if(IsSet($arguments['CompleteDelay'])) { $complete_delay=intval($arguments['CompleteDelay']*1000); if($complete_delay<=0) return('it was not specified a valid complete delay period'); $this->complete_delay=$complete_delay; } if(IsSet($arguments['ShowButton'])) { $button=$arguments['ShowButton']; if(strlen($button)==0) return('it was not specified a valid button input to show all options'); $this->button=$button; } if(IsSet($arguments['Dynamic']) && !$arguments['Dynamic']) $this->dynamic=0; if(IsSet($arguments['MenuClass'])) $this->menu_class=$arguments['MenuClass']; if(IsSet($arguments['MenuStyle'])) $this->menu_style=$arguments['MenuStyle']; if(IsSet($arguments['ItemClass'])) $this->item_class=$arguments['ItemClass']; if(IsSet($arguments['ItemStyle'])) $this->item_style=$arguments['ItemStyle']; if(IsSet($arguments['SelectedItemClass'])) $this->selected_item_class=$arguments['SelectedItemClass']; if(IsSet($arguments['SelectedItemStyle'])) $this->selected_item_style=$arguments['SelectedItemStyle']; $this->complete=$this->GenerateInputID($form, $this->input, '_'); if($this->dynamic) { $this->ajax=$this->complete.'ajax'; $ajax_arguments=array( 'TYPE'=>'custom', 'NAME'=>$this->ajax, 'ID'=>$this->ajax, 'CustomClass'=>'form_ajax_submit_class', 'TargetInput'=>$this->input ); if(IsSet($arguments['Timeout'])) $ajax_arguments['Timeout']=intval($arguments['Timeout']); if(IsSet($arguments['FeedbackElement'])) { $ajax_arguments['FeedbackElement']=$arguments['FeedbackElement']; if(IsSet($arguments['SubmitFeedback'])) $ajax_arguments['SubmitFeedback']=$arguments['SubmitFeedback']; if(IsSet($arguments['TimeoutFeedback'])) { $ajax_arguments['TimeoutFeedback']=$arguments['TimeoutFeedback']; $ajax_arguments['ONTIMEOUT']=''; } if(IsSet($arguments['CompleteFeedback'])) $ajax_arguments['CompleteFeedback']=$arguments['CompleteFeedback']; } } if(strlen($error=$this->GetCompleteValues($form, $arguments))) return($error); if((!$this->dynamic || (strlen($error=$form->AddInput($ajax_arguments))==0 && strlen($error=$form->Connect($this->ajax, $this->input, 'ONCOMPLETE', 'Reposition', array()))==0)) && (strlen($this->button)==0 || ((!$this->dynamic || strlen($error=$form->AddInput(array( 'TYPE'=>'hidden', 'NAME'=>$this->complete.'t', 'ID'=>$this->complete.'t', 'VALUE'=>'' )))==0) && strlen($error=$form->Connect($this->button, $this->input, 'ONCLICK', 'Show', array()))==0)) && strlen($error=$form->Connect($this->text, $this->input, 'ONBLUR', 'Hide', array('Delay'=>0.2)))==0 && strlen($error=$form->Connect($this->text, $this->input, 'ONKEYDOWN', 'ControlKeys', array()))==0) $error=$form->Connect($this->text, $this->input, 'ONKEYUP', 'Complete', array()); return($error); } Function GetJavascriptConnectionAction(&$form, $form_object, $from, $event, $action, &$context, &$javascript) { switch($action) { case 'Complete': $value=$form->GetJavascriptInputValue($form_object, $this->text); if(strlen($value)==0) return('it was not possible to determine how to retrieve value of '.$this->text); $javascript='if('.(strcmp($event,'ONKEYUP') ? '' : 'event.keyCode!=40 && event.keyCode!=38 && event.keyCode!=27 && event.keyCode!=13 && ').$value.'.length>='.$this->minimum_complete.'){ '.$this->complete.'w++; '.$this->complete.'f='.$form_object.'; setTimeout('."'".$this->complete."()',".$this->complete_delay.'); return false;};'; break; case 'Hide': $javascript=$this->complete.'h();'; $delay=(IsSet($context['Delay']) ? intval($context['Delay']*1000) : 0); if($delay) $javascript='setTimeout('.$form->EncodeJavascriptString($javascript).', '.$delay.');'; break; case 'Show': if($this->dynamic) { $submit_context=array('Validate'=>0); if(strlen($error=$form->GetJavascriptConnectionAction($form_object, $this->input, $this->ajax, 'ONSHOW', 'Submit', $submit_context, $complete_javascript))) return($error); $javascript=$this->complete.'f='.$form_object.'; '.$form->GetJavascriptSetInputValue($this->complete.'f', $this->complete.'t', $form->EncodeJavascriptString('a')).' '.$complete_javascript.';'; } else $javascript=$this->complete.'f='.$form_object.'; '.$this->complete.'bm('.$this->complete.'i, false); '.$form->GetJavascriptInputObject($form_object, $this->text).'.focus();'; $javascript='if(!'.$this->complete.'o) {'.$javascript.'} return false;'; break; case 'Reposition': $javascript=$this->complete.'rp(document.getElementById('.$form->EncodeJavascriptString($this->complete.'m').'), '.$form->GetJavascriptInputObject($form_object, $this->text).');'; break; case 'ControlKeys': $javascript='if('.$this->complete.'o) { if(event.keyCode==40 && '.$this->complete.'is<'.$this->complete.'co.length-1) { '.$this->complete.'si('.$this->complete.'is+1); '.$this->complete.'so(t,'.$this->complete.'is); return false; } if(event.keyCode==38 && '.$this->complete.'is>0) { '.$this->complete.'si('.$this->complete.'is-1);'.$this->complete.'so(t,'.$this->complete.'is); return false; } if(event.keyCode==27) { '.$this->complete.'h(); return false; } if(event.keyCode==13) { '.$this->complete.'h(); return true; } };'; break; default: return($this->DefaultGetJavascriptConnectionAction($form, $form_object, $from, $event, $action, $context, $javascript)); } return(''); } Function AddInputPart(&$form) { if($this->dynamic) { $submit_context=array('Validate'=>0); if(strlen($error=$form->GetJavascriptConnectionAction($this->complete.'f', $this->input, $this->ajax, 'ONCOMPLETE', 'Submit', $submit_context, $complete_javascript))) return($error); } $eol=$form->end_of_line; $b="\n"; $item_style=(strlen($this->item_style) ? $this->item_style : ';'); $selected_item_style=(strlen($this->selected_item_style) ? $this->selected_item_style : ';'); if(strlen($this->item_style_attributes)==0) { $this->item_style_attributes=(strlen($this->item_class) ? ' class="'.HtmlSpecialChars($this->item_class).'"' : '').((strlen($this->item_style) || strlen($this->selected_item_style)) ? ' style="'.HtmlSpecialChars($item_style).'"' : ''); } $menu=$form->EncodeJavascriptString($this->complete.'m'); $text_object = $form->GetJavascriptInputObject($this->complete.'f', $this->text); $html='
menu_class) ? ' class="'.HtmlSpecialChars($this->menu_class).'"' : '').' style="display: block; position: absolute; overflow: auto; visibility: hidden;'.HtmlSpecialChars($this->menu_style).'">
'.$b. ''; if(strlen($error=$form->AddDataPart($html)) || ($this->dynamic && strlen($error=$form->AddInputPart($this->ajax))) || (strlen($this->button) && (strlen($error=$form->AddInputPart($this->button)) || ($this->dynamic && strlen($error=$form->AddInputPart($this->complete.'t')))))) return($error); return(''); } Function Connect(&$form, $to, $event, $action, &$context) { switch($action) { case 'Complete': case 'Hide': case 'Show': case 'ControlKeys': return(''); default: return($this->DefaultConnect($form, $to, $event, $action, $context)); } } Function PostMessage(&$form, $message, &$processed) { if(strlen($error = $form->LoadInputValues())) return($error); $text=$form->GetInputValue($this->text); $all=(strlen($this->button) && !strcmp($form->GetInputValue($this->complete.'t'), 'a')); $found=array(); if(($all || strlen($text)>=$this->minimum_complete) && strlen($error=$this->SearchCompleteValues($form, $s=($all ? '' : strtolower($text)), $found))) $form->OutputError($error, $this->input); elseif(count($found)) { $results=$this->SerializeItems($form, $found); $s=$form->EncodeJavascriptString($s); $command=$message['Window'].'.'.$this->complete.'i='.$message['Window'].'.'.$this->complete.'c['.$s.']='.$results.'; if('.$message['Window'].'.'.$this->complete.'s.toLowerCase()=='.$s.') {'.$message['Window'].'.'.$this->complete.'bm('.$message['Window'].'.'.$this->complete.'i, '.($all ? 'false' : 'true').'); '.$form->GetJavascriptInputObject($message['Form'], $this->text).'.focus();}'; $message['Actions']=array( array( 'Action'=>'Command', 'Command'=>$command ) ); } return($form->ReplyMessage($message, $processed)); } }; ?>