无法在AngularJS + Stormpath中的注册表单中添加自定义字段

时间:2016-02-05 18:32:24

标签: stormpath

我想在新用户注册期间添加自定义字段,但它显示错误消息:

  

不是已配置的注册字段。

但第https://docs.stormpath.com/angularjs/sdk/#/api/stormpath.spRegistrationForm:spRegistrationForm页上的文档指出:

  

您提供的任何表单字段不是默认字段(名字,姓氏)之一,将自动放入新帐户的惯例数据对象中。

我使用的代码:



<form ng-submit="submit()">
	<div class="form-group">
		<input type="text" class="form-control" placeholder="First Name" ng-model="formModel.givenName" required="" ng-disabled="creating">
	</div>
	<div class="form-group">
		<input type="text" class="form-control" placeholder="Last Name" ng-model="formModel.surname" required="" ng-disabled="creating">
	</div>
	<div class="form-group">
		<input type="email" class="form-control" placeholder="Email" ng-model="formModel.email" required="" ng-disabled="creating">
	</div>
	<div class="form-group">
		<input type="password" class="form-control" placeholder="Password" ng-model="formModel.password" required="" ng-disabled="creating">
	</div>
	<div class="form-group">
		<input type="text" class="form-control" placeholder="Custom field" ng-model="formModel.customfield" required="" ng-disabled="creating">
	</div>
  
	<p class="alert alert-danger" ng-show="error>
	<button type="submit" class="btn btn-primary" ng-disabled="creating">Register</button>
</form>
&#13;
&#13;
&#13;

如何在注册表单上添加自定义字段?

3 个答案:

答案 0 :(得分:2)

我想为此处的任何人提交更新的答案。在挖掘node_modules/express-stormpath/lib/helpers/get-required-registration-fields.j之后,我在第26行注意到代码引用了config.web.register.fields,而文档引用了web.register.form.fields。通过移除form键并提升字段键,一切正常!

答案 1 :(得分:0)

从错误消息中可以看出您在后端使用我们的Express-Stormpath库(请告知我这是不正确的。)

您还需要在Express服务器中配置字段。我们还需要服务器端表单配置,以防止对用户的自定义数据对象的任意请求。

有关表单配置的文档,请访问:

http://docs.stormpath.com/nodejs/express/latest/registration.html#creating-custom-fields

希望这有帮助!附:我在Stormpath工作:)

答案 2 :(得分:0)

在服务器端,stormpath init应该是这样的

web: { 
produces: 
['application/json'],
 register: {
 enabled: true, 
 uri: '', 
form: {
 fields: 
{ organization_id: { enabled: true, required: true, } }
 } 
} 

==

相关问题