Skip to content

Commit fc46dd1

Browse files
committed
Updated the JavaScript associated with the search page to
control whether the 'search' button is enabled or not. It is now enabled if either the main search box has input, or if any of the sub-options have input, or both. Note that the Yahoo! widgets we were using did weird things to the button name, so I disabled that. This changes the look and feel of the button - that may be a contenious issue. OTOH, I think that this is probably a good thing, since this is the only place where we override the user's default appearance settings. Another possible issue is the use of JavaScript without JQuery. The existing code here did not use JQuery, so I decided to simply extend it. See the Trac ticket ietf-tools#480 for more. http://trac.tools.ietf.org/tools/ietfdb/ticket/480 - Legacy-Id: 2958
1 parent 1be0cbe commit fc46dd1

2 files changed

Lines changed: 61 additions & 21 deletions

File tree

shane/ietf/idrfc/views_search.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,34 @@
4242
from ietf.idrfc.idrfc_wrapper import IdWrapper,RfcWrapper,IdRfcWrapper
4343
from ietf.utils import normalize_draftname
4444

45+
def addInputEvents(widget):
46+
widget.attrs["oninput"] = 'inputEvent()'
47+
widget.attrs["onpropertychange"] = 'propertyChange()'
48+
49+
def addChangeEvent(widget):
50+
widget.attrs["onchange"] = 'changeEvent()'
51+
4552
class SearchForm(forms.Form):
4653
name = forms.CharField(required=False)
54+
addInputEvents(name.widget)
4755
rfcs = forms.BooleanField(required=False,initial=True)
4856
activeDrafts = forms.BooleanField(required=False,initial=True)
4957
oldDrafts = forms.BooleanField(required=False,initial=False)
5058
lucky = forms.BooleanField(required=False,initial=False)
5159

5260
by = forms.ChoiceField(choices=[(x,x) for x in ('author','group','area','ad','state')], required=False, initial='wg', label='Foobar')
5361
author = forms.CharField(required=False)
62+
addInputEvents(author.widget)
5463
group = forms.CharField(required=False)
64+
addInputEvents(group.widget)
5565
area = forms.ModelChoiceField(Area.active_areas(), empty_label="any area", required=False)
66+
addChangeEvent(area.widget)
5667
ad = forms.ChoiceField(choices=(), required=False)
68+
addChangeEvent(ad.widget)
5769
state = forms.ModelChoiceField(IDState.objects.all(), empty_label="any state", required=False)
70+
addChangeEvent(state.widget)
5871
subState = forms.ChoiceField(choices=(), required=False)
72+
addChangeEvent(subState.widget)
5973

6074
def __init__(self, *args, **kwargs):
6175
super(SearchForm, self).__init__(*args, **kwargs)

shane/ietf/templates/idrfc/search_form.html

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,39 +77,42 @@
7777

7878
<div style="padding-top:0.5em;">
7979
{# <input type="hidden" name="ajax" value="" /> #}
80-
<span id="search_submit_button" class="yui-button yui-submit-button">
8180
<span class="first-child">
82-
<button type="submit" id="search_submit">Search</button>
83-
</span>
81+
<button type="submit" name="search_submit" id="id_search_submit">Search</button>
8482
</span>
8583
</div>
8684

8785
</form>
8886

8987
<script type="text/javascript">
9088
//<![CDATA[
91-
{% comment %}
92-
function searchResult(o) {
93-
var el = document.getElementById("search_results");
94-
el.innerHTML = (o.responseText !== undefined) ? o.responseText : "?";
89+
// we want to disable our submit button if we have no search text,
90+
// and we have no advanced options selected
91+
function toggleSubmit() {
92+
var button = document.getElementById("id_search_submit");
93+
var by = findCheckedSearchBy();
94+
var value = findSearchByValue(by);
95+
var text = document.getElementById("id_name");
96+
if ((value == "") && (text.value == "")) {
97+
button.disabled = true;
98+
} else {
99+
button.disabled = false;
100+
}
95101
}
96102

97-
function searchFailure(o) {
98-
var el = document.getElementById("search_results");
99-
el.innerHTML = "Error: "+o.status+" "+o.statusText;
103+
// check our button status after every change to text fields
104+
// Internet Explorer uses 'onpropertychange', everyone else 'oninput'
105+
function inputEvent(event) {
106+
toggleSubmit();
107+
}
108+
function propertyChange() {
109+
toggleSubmit();
100110
}
101111

102-
function submitSearch() {
103-
document.getElementById("search_results").innerHTML = "Searching...";
104-
document.search_form.ajax.value = "1";
105-
YAHOO.util.Connect.setForm("search_form");
106-
YAHOO.util.Connect.asyncRequest('POST', '/doc/search/',
107-
{ success: searchResult,
108-
failure: searchFailure,
109-
argument: null
110-
}, null);
112+
// check our button status after every change to selection pulldowns
113+
function changeEvent(event) {
114+
toggleSubmit();
111115
}
112-
{% endcomment %}
113116

114117
function togglePlusMinus(id) {
115118
var el = document.getElementById(id);
@@ -123,7 +126,7 @@
123126
}
124127
}
125128

126-
function changeBy() {
129+
function findCheckedSearchBy() {
127130
var by='';
128131
var f = document.search_form;
129132
for (var i = 0; i < f.by.length; i++) {
@@ -132,6 +135,27 @@
132135
break;
133136
}
134137
}
138+
return by;
139+
}
140+
141+
function findSearchByValue(by) {
142+
if (by == 'author') { return document.getElementById("id_author").value; }
143+
if (by == 'group') { return document.getElementById("id_group").value; }
144+
if (by == 'area') { return document.getElementById("id_area").value; }
145+
if (by == 'ad') { return document.getElementById("id_ad").value; }
146+
if (by == 'state') {
147+
// state might be state...
148+
state_value = document.getElementById("id_state").value;
149+
if (state_value) { return state_value; }
150+
// ...or sub-state
151+
return document.getElementById("id_subState").value;
152+
}
153+
return '';
154+
}
155+
156+
function changeBy() {
157+
var by=findCheckedSearchBy();
158+
var f = document.search_form;
135159
f.author.disabled=true;
136160
f.group.disabled=true;
137161
f.area.disabled=true;
@@ -142,6 +166,8 @@
142166
if (by=='area') { f.area.disabled=false;}
143167
if (by=='ad') { f.ad.disabled=false; }
144168
if (by=='state') { f.state.disabled=false; f.subState.disabled=false; }
169+
170+
toggleSubmit();
145171
}
146172

147173
function toggleAdvanced() {

0 commit comments

Comments
 (0)