Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
problem-builder
Commits
c47fed9b
Commit
c47fed9b
authored
Apr 02, 2014
by
Alan Boudreault
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented min_characters for free text answer
parent
d1af936a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
7 deletions
+34
-7
mentoring/answer.py
+8
-2
mentoring/public/js/answer.js
+10
-1
mentoring/public/js/mentoring.js
+12
-3
mentoring/templates/html/answer_editable.html
+4
-1
No files found.
mentoring/answer.py
View file @
c47fed9b
...
...
@@ -29,7 +29,7 @@ from lazy import lazy
from
xblock.fragment
import
Fragment
from
.light_children
import
LightChild
,
Boolean
,
Scope
,
String
from
.light_children
import
LightChild
,
Boolean
,
Scope
,
String
,
Integer
from
.models
import
Answer
from
.utils
import
render_template
...
...
@@ -51,6 +51,8 @@ class AnswerBlock(LightChild):
read_only
=
Boolean
(
help
=
"Display as a read-only field"
,
default
=
False
,
scope
=
Scope
.
content
)
default_from
=
String
(
help
=
"If specified, the name of the answer to get the default value from"
,
default
=
None
,
scope
=
Scope
.
content
)
min_characters
=
Integer
(
help
=
"Minimum number of characters allowed for the answer"
,
scope
=
Scope
.
content
)
@lazy
def
student_input
(
self
):
...
...
@@ -106,7 +108,11 @@ class AnswerBlock(LightChild):
@property
def
completed
(
self
):
return
bool
(
self
.
read_only
or
self
.
student_input
)
answer_length_ok
=
self
.
student_input
if
self
.
min_characters
>
0
:
answer_length_ok
=
len
(
self
.
student_input
)
>=
self
.
min_characters
return
bool
(
self
.
read_only
or
answer_length_ok
)
def
save
(
self
):
"""
...
...
mentoring/public/js/answer.js
View file @
c47fed9b
function
AnswerBlock
(
runtime
,
element
)
{
return
{
submit
:
function
()
{
return
$
(
element
).
find
(
':input'
).
serializeArray
();
var
input
=
$
(
':input'
,
element
),
answer_length
=
input
.
val
().
length
,
data
=
input
.
data
();
if
(
_
.
isNumber
(
data
.
min_characters
)
&&
(
data
.
min_characters
>
0
)
&&
(
answer_length
<
data
.
min_characters
))
{
throw
"The answer has a minimum of "
+
data
.
min_characters
+
" characters."
;
}
return
input
.
serializeArray
();
},
handleSubmit
:
function
(
result
)
{
$
(
element
).
find
(
'.message'
).
text
((
result
||
{}).
error
||
''
);
...
...
mentoring/public/js/mentoring.js
View file @
c47fed9b
...
...
@@ -77,16 +77,25 @@ function MentoringBlock(runtime, element) {
var
submit_dom
=
$
(
element
).
find
(
'.submit .input-main'
);
submit_dom
.
bind
(
'click'
,
function
()
{
var
success
=
true
;
var
data
=
{};
var
children
=
getChildren
(
element
);
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
var
child
=
children
[
i
];
if
(
child
.
name
!==
undefined
)
{
data
[
child
.
name
]
=
callIfExists
(
child
,
'submit'
);
try
{
data
[
child
.
name
]
=
callIfExists
(
child
,
'submit'
);
}
catch
(
error
)
{
alert
(
error
);
success
=
false
;
}
}
}
var
handlerUrl
=
runtime
.
handlerUrl
(
element
,
'submit'
);
$
.
post
(
handlerUrl
,
JSON
.
stringify
(
data
)).
success
(
handleSubmitResults
);
if
(
success
)
{
var
handlerUrl
=
runtime
.
handlerUrl
(
element
,
'submit'
);
$
.
post
(
handlerUrl
,
JSON
.
stringify
(
data
)).
success
(
handleSubmitResults
);
}
});
// init children (especially mrq blocks)
...
...
mentoring/templates/html/answer_editable.html
View file @
c47fed9b
<textarea
class=
"answer editable"
cols=
"50"
rows=
"10"
name=
"input"
>
{{ self.student_input }}
</textarea>
<textarea
class=
"answer editable"
cols=
"50"
rows=
"10"
name=
"input"
data-min_characters=
"{{ self.min_characters }}"
>
{{ self.student_input }}
</textarea>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment