-%
-% my( %opt ) = @_;
-% $opt{'field_name'} ||= 'custnum';
-%
-% my $cust_main = '';
-% if ( $opt{'value'} ) {
-% $cust_main = qsearchs(
-% 'table' => 'cust_main',
-% 'hashref' => { 'custnum' => $opt{'value'} },
-% 'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql,
-% );
-% }
-%
-
-
-<INPUT TYPE="hidden" NAME="<% $opt{'field_name'} %>" VALUE="<% $opt{'value'} %>">
+<%doc>
-<!-- some false laziness w/ misc/batch-cust_pay.html, though not as bad as i'd thought at first... -->
+Example:
+
+ include( '/elements/search-cust_main.html,
+ 'field' => 'custnum',
+ #slightly deprecated old synonym for field#'field_name'=>'custnum',
+ 'find_button' => 1, #add a "find" button to the field
+ 'curr_value' => 54, #current value
+ 'value => 32, #deprecated synonym for curr_value
+ );
-<INPUT TYPE="text" NAME="<% $opt{'field_name'} %>_search" ID="<% $opt{'field_name'} %>_search" SIZE="32" VALUE="<% $cust_main ? $cust_main->name : '(cust #, name or company)' %>" onFocus="clearhint_<% $opt{'field_name'} %>_search(this);" onClick="clearhint_<% $opt{'field_name'} %>_search(this);" onChange="smart_<% $opt{'field_name'} %>_search(this);">
+</%doc>
+<INPUT TYPE="hidden" NAME="<% $field %>" ID="<% $field %>" VALUE="<% $value %>">
+
+<!-- some false laziness w/ misc/batch-cust_pay.html, though not as bad as i'd thought at first... -->
-<SELECT NAME="<% $opt{'field_name'} %>_select" ID="<% $opt{'field_name'} %>_select" STYLE="color:#ff0000; display:none" onChange="select_<% $opt{'field_name'} %>(this);">
+<INPUT TYPE = "text"
+ NAME = "<% $field %>_search"
+ ID = "<% $field %>_search"
+ SIZE = "32"
+ VALUE="<% $cust_main ? $cust_main->name : '(cust #, name or company)' |h %>"
+ onFocus="clearhint_<% $field %>_search(this);"
+ onClick="clearhint_<% $field %>_search(this);"
+ onChange="smart_<% $field %>_search(this);"
+>
+
+% if ( $opt{'find_button'} ) {
+ <INPUT TYPE = "button"
+ VALUE = 'Find',
+ NAME = "<% $field %>_findbutton"
+ onClick = "smart_<% $field %>_search(this.form.<% $field %>_search);"
+ >
+% }
+
+<SELECT NAME="<% $field %>_select" ID="<% $field %>_select" STYLE="color:#ff0000; display:none" onChange="select_<% $field %>(this);">
</SELECT>
<% include('/elements/xmlhttp.html',
<SCRIPT TYPE="text/javascript">
- function clearhint_<% $opt{'field_name'} %>_search (what) {
+ function clearhint_<% $field %>_search (what) {
what.style.color = '#000000';
}
- function smart_<% $opt{'field_name'} %>_search(what) {
+ var <% $field %>_search_active = false;
+
+ function smart_<% $field %>_search(what) {
+
+ if ( <% $field %>_search_active )
+ return;
var customer = what.value;
what.style.color= '#000000';
what.style.backgroundColor = '#dddddd';
- var customer_select = document.getElementById('<% $opt{'field_name'} %>_select');
+ var customer_select = document.getElementById('<% $field %>_select');
//alert("search for customer " + customer);
- function <% $opt{'field_name'} %>_search_update(customers) {
+ function <% $field %>_search_update(customers) {
//alert('customers returned: ' + customers);
if ( customerArray.length == 0 ) {
- what.form.<% $opt{'field_name'} %>.value = '';
+ what.form.<% $field %>.value = '';
what.value = 'Customer not found: ' + what.value;
what.style.color = '#ff0000';
//alert('one customer found: ' + customerArray[0]);
- what.form.<% $opt{'field_name'} %>.value = customerArray[0][0];
+ what.form.<% $field %>.value = customerArray[0][0];
what.value = customerArray[0][1];
what.style.display = '';
}
+ <% $field %>_search_active = false;
+
}
- smart_search( customer, <% $opt{'field_name'} %>_search_update );
+ <% $field %>_search_active = true;
+
+ smart_search( customer, <% $field %>_search_update );
}
- function select_<% $opt{'field_name'} %> (what) {
+ function select_<% $field %> (what) {
var custnum = what.options[what.selectedIndex].value;
var customer = what.options[what.selectedIndex].text;
- var customer_obj = document.getElementById('<% $opt{'field_name'} %>_search');
+ var customer_obj = document.getElementById('<% $field %>_search');
if ( custnum == '' ) {
//what.style.color = '#ff0000';
} else {
- what.form.<% $opt{'field_name'} %>.value = custnum;
+ what.form.<% $field %>.value = custnum;
customer_obj.value = customer;
customer_obj.style.color = '#000000';
}
</SCRIPT>
+<%init>
+
+my( %opt ) = @_;
+
+my $field = $opt{'field'} || $opt{'field_name'} || 'custnum';
+
+my $value = $opt{'curr_value'} || $opt{'value'};
+
+my $cust_main = '';
+if ( $value ) {
+ $cust_main = qsearchs({
+ 'table' => 'cust_main',
+ 'hashref' => { 'custnum' => $value },
+ 'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql,
+ });
+}
+</%init>