Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1f2badf

Browse filesBrowse files
Merge pull request googlecodelabs#228 from googlecodelabs/survey-fix
Fix the ID of radio buttons so that they are unique for each questions.
2 parents 542dc91 + 1bc373f commit 1f2badf
Copy full SHA for 1f2badf

File tree

Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed
Open diff view settings
Collapse file

‎codelab-elements/google-codelab-survey/google_codelab_survey.js‎

Copy file name to clipboardExpand all lines: codelab-elements/google-codelab-survey/google_codelab_survey.js
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class CodelabSurvey extends HTMLElement {
195195
polymerRadioEls.forEach(radioEl => {
196196
const title = radioEl.textContent;
197197
surveyOptions.push({
198-
radioId: this.normalizeIdAttr_(title),
198+
radioId: this.normalizeIdAttr_(questionEls[index].textContent, title),
199199
radioTitle: title
200200
});
201201
});
@@ -220,7 +220,7 @@ class CodelabSurvey extends HTMLElement {
220220
const surveyData = this.storedData_[this.surveyName_];
221221
if (surveyData) {
222222
Object.keys(surveyData).forEach(key => {
223-
const id = this.normalizeIdAttr_(surveyData[key]);
223+
const id = this.normalizeIdAttr_(key, surveyData[key]);
224224
/** @type {?HTMLInputElement} */
225225
const inp = /** @type {?HTMLInputElement} */ (
226226
this.querySelector(`#${id}`));
@@ -232,12 +232,14 @@ class CodelabSurvey extends HTMLElement {
232232
}
233233

234234
/**
235-
* @param {string} id
235+
* @param {string} question
236+
* @param {string} answer
236237
* @return {string}
237238
* @private
238239
*/
239-
normalizeIdAttr_(id) {
240-
return id.replace(/\s+/g, '-').replace(/[^a-zA-Z0-9 \-]/g, '').toLowerCase();
240+
normalizeIdAttr_(question, answer) {
241+
return `${question}--${answer}`.replace(/\s+/g, '-')
242+
.replace(/[^a-zA-Z0-9 \-]/g, '').toLowerCase();
241243
}
242244

243245
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.