[LON-CAPA-cvs] cvs: loncom /homework inputtags.pm structuretags.pm
raeburn
raeburn at source.lon-capa.org
Mon Sep 15 13:45:35 EDT 2014
raeburn Mon Sep 15 17:45:35 2014 EDT
Modified files:
/loncom/homework inputtags.pm structuretags.pm
Log:
Bug 6740
Eliminate multiple submissions of same form. Work in progress.
- Pressing "Enter" key within a text input field submits form.
- When this occurs make textbox readonly, and submit button disabled.
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.325 loncom/homework/inputtags.pm:1.326
--- loncom/homework/inputtags.pm:1.325 Sun Sep 14 15:21:43 2014
+++ loncom/homework/inputtags.pm Mon Sep 15 17:45:35 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.325 2014/09/14 15:21:43 raeburn Exp $
+# $Id: inputtags.pm,v 1.326 2014/09/15 17:45:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -235,6 +235,7 @@
my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
$result='';
my $tagident = 'HWVAL_' . $resid;
+ my $itemid = 'HWVAL_'.$partid.'_'.$resid;
if ($addchars) {
$result.=&addchars($tagident, $addchars);
}
@@ -243,7 +244,7 @@
'externalresponse')) {
$textareaclass = 'class="LC_richDetectHtml spellchecked"';
}
- $result.= '<textarea wrap="hard" name="'.$tagident.'" id="'.$tagident.'" ' .
+ $result.= '<textarea wrap="hard" name="'.$tagident.'" id="'.$itemid.'" ' .
'rows="'.$rows.'" cols="'.$cols.'" '.$textareaclass
.'>'.
&HTML::Entities::encode($oldresponse,'<>&"');
@@ -325,10 +326,11 @@
my $spellcheck = &Apache::lonxml::get_param('spellcheck', $parstack, $safeeval);
$Apache::lonxml::evaluate++;
if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
+ my $partid=$Apache::inputtags::part;
my $resid = $Apache::inputtags::response[-1];
- my $tagident = 'HWVAL_' . $resid;
+ my $itemid = 'HWVAL_' . $partid . '_' . $resid;
my $result = "</textarea>";
- $result .= &spellcheck_onblur($tagident, $spellcheck);
+ $result .= &spellcheck_onblur($itemid, $spellcheck);
return $result;
}
} elsif ($target eq 'edit') {
@@ -457,18 +459,19 @@
$readonly='';
}
my $name = 'HWVAL_'.$id;
+ my $itemid = 'HWVAL_'.$partid.'_'.$id;
if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
$name = "none";
}
$result.= '<input onkeydown="javascript:setSubmittedPart(\''.$partid.'\');"'
. ' type="text" '
. $readonly.' name="'. $name . '"'
- . ' id="' . $name . '"'
+ . ' id="' . $itemid . '"'
. ' value="'. $oldresponse.'"'
- . ' class="spellchecked" size="'.$size.'"'.$maxlength
+ . ' class="LC_textline spellchecked" size="'.$size.'"'.$maxlength
. '/>';
- $result .= &spellcheck_onblur($name, $spellcheck);
+ $result .= &spellcheck_onblur($itemid, $spellcheck);
}
if ($Apache::lonhomework::type eq 'exam'
&& &needs_exam_box($tagstack)) {
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.520 loncom/homework/structuretags.pm:1.521
--- loncom/homework/structuretags.pm:1.520 Sun Sep 14 15:21:43 2014
+++ loncom/homework/structuretags.pm Mon Sep 15 17:45:35 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.520 2014/09/14 15:21:43 raeburn Exp $
+# $Id: structuretags.pm,v 1.521 2014/09/15 17:45:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -256,23 +256,42 @@
}
var submithandled = 0;
+var keypresshandled = 0;
$(document).ready(function(){
+
+ $(document).keypress(function(event){
+ var keycode = (event.keyCode ? event.keyCode : event.which);
+ if ((keycode == '13') && (keypresshandled == 0)) {
+ if ( $( document.activeElement ).hasClass("LC_textline") ) {
+ keypresshandled = 1;
+ var idsArray = $( document.activeElement ).attr("id").split(/HWVAL_/);
+ if (idsArray.length) {
+ event.preventDefault();
+ var itemsArray = idsArray[1].split(/_/);
+ var buttonId = idsArray[0]+'submit_'+itemsArray[0];
+ $("#"+buttonId).trigger("click");
+ }
+ }
+ }
+ });
+
$(document).delegate('form :submit', 'click', function( event ) {
if ( $( this ).hasClass( "LC_hwk_submit" ) ) {
var buttonId = this.id;
if (submithandled == 0) {
submithandled = 1;
$( "#msg_"+buttonId ).css({"display": "inline","background-color": "#87cefa",
- "color": "black","padding": "2px"}) ;
+ "color": "black","padding": "2px"}) ;
$( ".LC_status_"+buttonId ).hide();
- if (( $(this.form).id == "LC_page" ) && ($('input[name="all_submit"]').length )) {
+ if (( $(this.form).id == "LC_page" ) && ($('input[name="all_submit"]').length )) {
if (( "#"+buttonId+"_pressed" ).length) {
$( "#"+buttonId+"_pressed" ).val( "1" );
}
}
$(this.form).submit();
- $( this ).attr( "disabled", true);
+ $( ".LC_hwk_submit" ).prop( "disabled", true);
+ $( ".LC_textline" ).prop( "readonly", "readonly");
event.preventDefault();
return true;
}
@@ -280,6 +299,7 @@
});
});
+
// ]]>
</script>
JS
More information about the LON-CAPA-cvs
mailing list