I am trying to get data from a form in Dart webComponent. The following LoginComponent is defined.
doLogin function is not called when submit button is clicked. Tried placing on-click handler on submit button but that does not work either.
<html><body>
<element name="x-login" constructor="LoginComponent" extends="div">
<template >
<form id='loginForm' on-submit='doLogin()'>
<div>
<h1>Login :</h1>
<label for="loginName">Login name</label>
<input type="text" required="required" data-bind="value:loginId" />
<label>Password</label>
<input type="password" required="required" data-bind="value:pwd" />
<input type='submit' value="Login" />
<input type='button' data-action="click:doCancel" value="Cancel" />
<span>{{errorMessage}}</span></div>
</div>
</form>
</template>
<script type="application/dart">
import 'package:web_components/web_components.dart';
import 'ouremr.dart';
import 'dart:html';
class LoginComponent extends WebComponent {
String errorMessage="";
String loginId='';
String pwd='';
}
void doLogin(e) {
print("in do login");
e.preventDefault();
print(loginId);
print(pwd);
}
void doCancel(e) {
e.preventDefault();
errorMessage=' ';
style.display='none';
}
}
</script>
</element>
</body></html>
doLogin function is not called when form is submitted.
Tried following but that does not work either:
<input type='submit' value="Login" on-click='onLogin()'/>
thanks for the question! Really cool to see you playing with Dart’s Web UI libraries.
I cleaned up your code, and with a few tweaks, it works!
</div>in your template$eventto your on-click expressionsSee here for the code:
and
Hope that helps!
(note, the above code works with version 0.2.7 of dart_web_components)