tailieunhanh - Web to py enterprise web framework - p 30
THE AJAX FUNCTION 275 and the associated "default/" view: 1 2 3 4 5 {{extend ''}} This allows for more articulated responses than simple strings. Auto-completion Another application of the above ajax function is auto-completion. Here we wish to create an input field that expects a month name and, when the visitor types an incomplete name, performs auto-completion via an Ajax request. In response, an auto-completion drop-box appears below the input field. This can be achieved via the following default controller: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 def month_input(): return dict() def month_selector(): if not. | THE AJAX FUNCTION 275 1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 andthe associated default view extend form input id name onkeyup ajax echo name eval form div id target div This allows for more articulated responses than simple strings. Auto-completion Another application of the above ajax function is auto-completion. Here we wish to create an input field that expects a month name and when the visitor types an incomplete name performs auto-completion via an Ajax request. In response an auto-completion drop-box appears below the input field. This can be achieved via the following default controller def month_input return diet def month_seleetor if not return months January February March April May June July August September October November December selected m for m in months if return .join DIV k _oneliek jQuery month .val s k _onmouseover yellow _onmouseout white .xml for k in seleeted and the corresponding default month view extend style suggestions position relative .suggestions baekground white border solid 1px 55A6C8 .suggestions DIV padding 2px 4px 2px 4px style form input type text id month style width 250px br div style position absolute id suggestions elass suggestions div form seript jQuery month .keyup funetion ajax complete month suggestions seript 276 AJAX RECIPES 1 2 3 1 1 2 3 4 5 6 7 8 9 10 11 12 13 The jQuery script in the view triggers the Ajax request each time the visitor types something in the month input field. The value of the input field is submitted with the Ajax request to the month_selector action. This action finds a list of month names that start with the submitted text selected builds a list of DIVs each one containing a suggested month name and returns a string with the serialized DIVs. The view displays the response HTML in the .
đang nạp các trang xem trước