FEATURE: new 'required' survey attribute to control if all the fields are required to be completed

FEATURE: new ‘required’ survey attribute to control if all the fields are required to be completed

diff --git a/assets/javascripts/initializers/extend-for-survey.js.es6 b/assets/javascripts/initializers/extend-for-survey.js.es6
index 9b0ca7c..cf7133c 100644
--- a/assets/javascripts/initializers/extend-for-survey.js.es6
+++ b/assets/javascripts/initializers/extend-for-survey.js.es6
@@ -71,6 +71,7 @@ function initializeSurveys(api) {
     $surveys.each((idx, surveyElem) => {
       const $survey = $(surveyElem);
       const surveyName = $survey.data("survey-name");
+      const fieldsRequired = $survey.data("survey-required");
       let survey = surveys[surveyName];
 
       if (survey) {
@@ -78,6 +79,7 @@ function initializeSurveys(api) {
           id: `${surveyName}-${post.id}`,
           post,
           survey,
+          fieldsRequired,
           response: {}
         };
         const glue = new WidgetGlue("discourse-survey", register, attrs);
diff --git a/assets/javascripts/lib/discourse-markdown/survey.js.es6 b/assets/javascripts/lib/discourse-markdown/survey.js.es6
index 0865be0..e9c0f1e 100644
--- a/assets/javascripts/lib/discourse-markdown/survey.js.es6
+++ b/assets/javascripts/lib/discourse-markdown/survey.js.es6
@@ -4,6 +4,7 @@ import I18n from "I18n";
 const DATA_PREFIX = "data-survey-";
 const DEFAULT_SURVEY_NAME = "survey";
 const WHITELISTED_ATTRIBUTES = [
+  "required",
   "max",
   "min",
   "name",
diff --git a/assets/javascripts/widgets/discourse-survey.js.es6 b/assets/javascripts/widgets/discourse-survey.js.es6
index 02ff5c2..9bdab6a 100644
--- a/assets/javascripts/widgets/discourse-survey.js.es6
+++ b/assets/javascripts/widgets/discourse-survey.js.es6
@@ -360,8 +360,7 @@ export default createWidget("discourse-survey", {
     let cssClasses = "survey";
     return {
       class: cssClasses,
-      "data-survey-name": attrs.survey.get("name"),
-      "data-survey-type": attrs.survey.get("type")
+      "data-survey-name": attrs.survey.get("name")
     };
   },
 
@@ -426,8 +425,11 @@ export default createWidget("discourse-survey", {
     }
 
     const respondedFieldCount = Object.keys(attrs.response).length;
-    const totalFieldCount = attrs.survey.fields.length;
+    if (!attrs.fieldsRequired && respondedFieldCount > 0) {
+      return true;
+    }
 
+    const totalFieldCount = attrs.survey.fields.length;
     return totalFieldCount === respondedFieldCount;
   },
 

GitHub sha: 9d13c594