Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-9219: Fix editing known languages field in user profile form #472

Merged
merged 3 commits into from
Feb 20, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions root/account/edit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
</span>
[% extra_field = form.field('languages').field(form.field('languages').add_extra(1) - 1) %]
<span id="add-language-template" style="display: none">
[% r.select(extra_field.field('language_id'), id => 'fluency-template', class => 'language_id',) %]
[% r.select(extra_field.field('fluency'), class => 'fluency') %]
[% r.select(extra_field.field('language_id'), id => 'id-language-id-template', class => 'language_id', name => 'language-id-template') %]
[% r.select(extra_field.field('fluency'), id => 'id-fluency-template', class => 'fluency', name => 'fluency-template') %]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I'm wondering is, are these id and name attributes actually needed? It seems they aren't used anywhere and are just overridden in the script below, so we can just remove them.

Copy link
Contributor Author

@yvanzo yvanzo Feb 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed ids are of no use. They had to be unique, hence the override, but removal is even better. Only names are needed for form submission. And yes, template’s name is worthless. Cleaned up in 547b27e

<span class="buttons inline">
<button type="button" class="remove negative">[% l('Remove') %]</button>
</span>
Expand All @@ -77,6 +77,8 @@

<script>//<![CDATA[
$(function () {
$(document.body).append( $('#add-language-template') );

var languageCount = $('li.language').size();

$('#edit-profile-form').on('click', 'button.remove', function (event) {
Expand All @@ -87,15 +89,19 @@
$('button.another').click(function (event) {
event.preventDefault();

languageCount++;

var newLanguage = $('<li>').append($('#add-language-template').clone().contents());
newLanguage.find('select.language_id').attr('id',
'id-profile.languages.' + languageCount + '.language_id');
newLanguage.find('select.language_id').attr('name',
'profile.languages.' + languageCount + '.language_id');
newLanguage.find('select.fluency').attr('id',
'id-profile.languages.' + languageCount + '.fluency');
newLanguage.find('select.fluency').attr('name',
'profile.languages.' + languageCount + '.fluency');

$(this).parents('li').before(newLanguage);

languageCount++;
});
});
//]]></script>
Expand Down