Skip to content

Instantly share code, notes, and snippets.

@luki
Created November 12, 2016 23:15
Show Gist options
  • Save luki/5272e254002b6a298f8c15c552d3347e to your computer and use it in GitHub Desktop.
Save luki/5272e254002b6a298f8c15c552d3347e to your computer and use it in GitHub Desktop.
Map of InputElement Query Selectors
import 'qsmap.dart';
// An example using the helper 'qsmap.dart'
void submitAction(MouseEvent event) {
List parameters = ["name", "email", "body"];
String name;
String email;
String body;
Map values = getValues(parameters);
for (var parameter in parameters) {
switch (parameter) {
case "name":
name = values[parameter];
break;
case "email":
email = values[parameter];
break;
case "body":
body = values[parameter];
break;
default:
print("Error");
}
}
print(name);
print(email);
print(body);
/* Through this, you are able to create a list of names of input elements, and obtain their values easily by the followingly
returned map. */
// Returns value of querySelector
String returnInputText(String nameOfQuery) => (querySelector("#${nameOfQuery}") as InputElement).value;
// Returns a map of values of querySelectors
Map getValues(List<String> values) {
Map mapOfValues = new Map();
for (int i = 0; i < values.length; i++) {
String value = values[i];
mapOfValues["$value"] = returnInputText("$value");
}
return mapOfValues;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment