Alfresco分享客户端同步表单验证

编程入门 行业动态 更新时间:2024-10-09 12:34:40
本文介绍了Alfresco分享客户端同步表单验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在注册场景中拥有一个Alfresco Share客户端表单,我想验证是否选择了用户名。

我可以添加一个Alfresco表单验证器以同步的方式吗?

到目前为止,我的表单是这样的:

this.widgets.saveForm = new Alfresco.forms.Form(this.id +-form); this.widgets.saveForm.addValidation(Dom.get(this.id +-username),this.validateUsername,me,blur,this.msg(validation-hint.username-taken) );

但 this.validateUsername 需要创建一个 Alfresco.util .Ajax.request 添加到回购端Web服务,该服务将检查所选用户名的可用性。所以基本上,到了响应时间为止,我的原始validateUsername方法已经完成,返回false(很可能)。

到目前为止,我的进度是禁用提交按钮(这就是为什么我将 me 传递给验证处理程序的原因),并且如果用户名无误,则使用成功/失败回调函数启用它。

如果有更好的方法来设置验证处理程序的作用域为 this ,而不是传递我(这也是可行的,这是为了确保我不会错过更好的方式)。

$ b

解决方案

我的解决方法是这样的: $ b

  • 为表单添加一个自定义验证,并为验证器函数传递var me = this以获取作用域。

    this.widgets.saveForm.addValidation(Dom .get(this.id +-username), this.validateUsername ,我,blur,this.msg(validation-hint.username-taken));

  • 添加一个验证处理函数,它将a。禁用提交按钮并将检查CSS类设置为适当的形式以供用户获得反馈。代码片段:

    validateUsername:function Reg_validateUsername(el,me){ var val = this.fieldId.value; var username = trim(val); me.widgets.registerButton.set(disabled,true); Dom.addClass(me.id +-username-img,checking); Dom.removeClass(me.id +-username-img,hidden); Alfresco.util.Ajax.request({ url:/ alfresco / service / slingshot / register / username-available?username =+ username ,method:GET,successCallback:{ fn:me.onUsernameAvailable ,范围:me } ,failureCallback:{ fn:me.onUsernameTaken ,范围:me } });

  • 写一个后端webscript username-available.get 只有当用户名是免费的(并且是有效的,即使我有另一个验证程序),也能返回成功。

  • 提交按钮以再次启用并再次运行验证(因为其他字段)并将CSS类更改为有效。
  • strong>将CSS class设置为taken。

  • 这就是我最终这样做的结果。

    >

    I have an Alfresco Share client-side Form in a registration scenario and I want to validate if the chosen username is taken.

    Can I add a Alfresco forms validator in a synchronous way?

    So far my form goes something like this:

    this.widgets.saveForm = new Alfresco.forms.Form(this.id + "-form"); this.widgets.saveForm.addValidation(Dom.get(this.id + "-username"), this.validateUsername, me, "blur", this.msg("validation-hint.username-taken"));

    But this.validateUsername needs to make an Alfresco.util.Ajax.request to a repo-side web service which checks availability for the chosen username. So basically, by the time the response is here, my original validateUsername method is long-finished, returning false (likely).

    My progress so far is to disable the submit button (that is why I am passing "me" to the validation handler), and have success/failure callbacks enable it if the username is fine.

    What would be a decent way to make a synchronous validator?

    A side question would be if there is a better way to set the scope of the validation handler to "this", as opposed to passing me (this one works too, this is just to make sure I am not missing a better way).

    解决方案

    My workaround solution is this:

  • Add a custom validation to the form, and pass the "var me = this" for the validator function to get the scope.

    this.widgets.saveForm.addValidation(Dom.get(this.id + "-username"), this.validateUsername, me, "blur", this.msg("validation-hint.username-taken"));

  • Add a validation handler function which will a. disable the submit button and set the "checking" CSS class to the appropriate form for the user to have feedback. Code snip:

    validateUsername: function Reg_validateUsername(el, me) { var val = this.fieldId.value; var username = trim(val); me.widgets.registerButton.set("disabled", true); Dom.addClass(me.id + "-username-img", "checking"); Dom.removeClass(me.id + "-username-img", "hidden"); Alfresco.util.Ajax.request({ url: "/alfresco/service/slingshot/register/username-available?username=" + username , method: "GET" , successCallback: { fn: me.onUsernameAvailable , scope: me } , failureCallback: { fn: me.onUsernameTaken , scope: me } });

  • Write a backend webscript username-available.get that will return success only if the username is free (and valid, even though I have another validator for that).

  • onUsernameAvailable will set the submit button to enabled again and run validation again (because of other fields) and change the CSS class to "valid".

  • onUsernameTaken will set the CSS class to "taken".

  • That's how I ended up doing this.

    更多推荐

    Alfresco分享客户端同步表单验证

    本文发布于:2023-11-28 10:45:19,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:表单   客户端   Alfresco

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!