(Select template) |
(form data definition) |
||
Line 1: | Line 1: | ||
{| class="nicetable" | |||
|+ Form data compilation for display | |||
|- | |||
!width="50%"|Type A | |||
!width="50%"|Type B | |||
|- | |||
| <code javascript> | |||
var frm = new form(); | |||
frm.addFieldset('general', 'General'); | |||
textfield = new text(); | |||
textfield.set_name('title'); | |||
textfield.set_id('mod_lesson_title_' + pageid); | |||
textfield.set_label('Page Title'); | |||
textfield.set_required(); | |||
textfield.set_text(lesson.pages[pageid].title); | |||
frm.addElement(textfield); | |||
selectfield = new selectElement(); | |||
selectfield.set_name('Jump_1'); | |||
selectfield.set_label('Jumps'); | |||
selectfield.set_id("mod_lesson_jump_1_" + pageid); | |||
selectfield.set_options(joptions); | |||
frm.addElement(selectfield); | |||
$.when(frm.printForm()).then(function(tempformstuff) { | |||
$('.mod_lesson_pages').append(tempformstuff); | |||
$('#mod_lesson_editor_save_btn').click(function() { | |||
// Could do client side validation here. | |||
if ($("#mod_lesson_title_" + pageid).val() == "") { | |||
var textelement = $("#fitem_mod_lesson_title_" + pageid); | |||
frm.handleError('title', textelement, 'text', 'Title should not be empty'); | |||
} else { | |||
lesson.pages[pageid].save_edit_form(frm); | |||
} | |||
}); | |||
$('#mod_lesson_editor_cancel_btn').click(function() { | |||
$('.mod_lesson_page_editor').remove(); | |||
}); | |||
}); | |||
</code> | |||
| <code javascript> | |||
var formdata = { | |||
lessonpagetype: lesson.pages[pageid].qtypestring, | |||
pageid: pageid, | |||
title: { | |||
id: "mod_lesson_title_" + pageid, | |||
label: "Page Title", | |||
name: "title", | |||
text: lesson.pages[pageid].title, | |||
required: 1 | |||
}, | |||
contents: lesson.pages[pageid].contents, | |||
select: { | |||
id: pageid, | |||
label: "Jumps", | |||
name: "Jump_1", | |||
options: formfactory.formatOptions(joptions), | |||
helpButton: "<button type=\"button\">Help is here</button>" | |||
} | |||
}; | |||
$.when(templates.render('mod_lesson/page_editor', formdata)).done(function(pageeditor) { | |||
$('.mod_lesson_pages').append(pageeditor); | |||
$('#mod_lesson_editor_save_btn').click(function() { | |||
// Do client side validation. | |||
var titleelement = $("#mod_lesson_title_" + pageid); | |||
if (titleelement.val() == "") { | |||
var errors = { | |||
errors: { | |||
name: "title", | |||
message: "The lesson page title should not be empty" | |||
} | |||
}; | |||
formfactory.handleErrors(errors, formdata); | |||
} else { | |||
lesson.pages[pageid].save_edit_form(formdata); | |||
} | |||
}); | |||
$('#mod_lesson_editor_cancel_btn').click(function() { | |||
$('.mod_lesson_page_editor').remove(); | |||
}); | |||
}); | |||
</code> | |||
|} | |||
==Template for a select element== | ==Template for a select element== | ||
Same for both. | Same for both. |
Revision as of 01:24, 26 November 2015
Type A | Type B |
---|---|
|
|
Template for a select element
Same for both.
<label {{#hiddenLabel}}class="accesshide"Adrian Greeve/form comparison/hiddenLabel for="Template:id">
Template:label
{{#required}}{{>core/form-required}}Adrian Greeve/form comparison/required
{{#advanced}}{{>core/form-advanced}}Adrian Greeve/form comparison/advanced
</label>
{{{helpButton}}}
{{#error}}
{{{error}}}
Adrian Greeve/form comparison/error
<select name="Template:name" id="Template:id" {{#required}}requiredAdrian Greeve/form comparison/required {{#size}}size="Template:size"Adrian Greeve/form comparison/size>
{{#options}}
<option value="Template:value" {{#selected}}selectedAdrian Greeve/form comparison/selected>Template:text</option>
Adrian Greeve/form comparison/options
</select>
Type A | Type B |
---|---|
|
Type A | Type B |
---|---|
|
|