【问题标题】:How to override the crowd-html submit button to include additional data如何覆盖 crowd-html 提交按钮以包含其他数据
【发布时间】:2019-11-11 19:21:05
【问题描述】:

我正在使用 crowd-html 元素制作一个相当简单的表单,这使得一切都变得非常简单。作为我们研究的一部分,我们想看看工人如何与表单交互,所以我们有一堆基本的 JS 日志记录。这一切都准备为 JSON,其想法是使用 AWS API Gateway 和 AWS Lambda 记录它。代码似乎都在单元测试中工作,但不是真正的形式。我正在尝试这样做:

document.querySelector('crowd-form').onsubmit = function (e) {
  if (!validateForm()) {
    window.alert("Please check the form carefully, it isn't filled out completely!");
    e.preventDefault();
  } else {
    let event_data = {
      'specific_scroll_auditor': auditor_scrolled_pixels_specific.submit_callable(),
      'specific_clicks_auditor': auditor_clicks_specific.submit_callable(),
      'mouse_movements_total': auditor_mouse_movement_total.submit_callable(),
      'on_focus_time': auditor_on_focus_time.submit_callable(),
      'total_task_time': auditor_total_task_time.submit_callable(),
      'focus_changes': auditor_focus_changes.submit_callable()
    };
    log_client_event('auditors', event_data);
    post_event_log()
  }
}

请注意,验证位有效,但日志记录无效。我已经自己测试了 post_event_log() ,它工作得很好,所以看起来要么 1) 出于某种原因我从来没有遇到过 else 子句,或者 2) 提交发生的速度比我调用日志记录函数的速度要快. (但是为什么,因为验证有效?)

我也试过这个,借鉴了我​​们的灵感来自土耳其代码 (https://github.com/CuriousG102/turkey)。

$(window).ready(function () {
  window.onbeforeunload = function () {
    let event_data = {
      'specific_scroll_auditor': auditor_scrolled_pixels_specific.submit_callable(),
      'specific_clicks_auditor': auditor_clicks_specific.submit_callable(),
      'mouse_movements_total': auditor_mouse_movement_total.submit_callable(),
      'on_focus_time': auditor_on_focus_time.submit_callable(),
      'total_task_time': auditor_total_task_time.submit_callable(),
      'focus_changes': auditor_focus_changes.submit_callable()
    };
    log_client_event('auditors', event_data);
    post_event_log()
  }
});

这也行不通。我宁愿像上面那样以某种简单的方式来做这件事,而不是完全重写提交函数,但也许我必须这样做?

【问题讨论】:

    标签: javascript mechanicalturk


    【解决方案1】:

    您的自定义 UI 放置在 Ground Truth 的沙盒 iFrame 中。它仅用于实际工作,而不用于预览(您的代码可能在从 AWS 控制台预览 UI 时工作)。 iFrame 上的沙盒属性是这样的

    sandbox="allow-scripts allow-same-origin allow-forms"
    

    有关说明,请参阅 https://www.w3schools.com/tags/att_iframe_sandbox.asp。无论是否存在 allow-same-origin(不是您可以以任何方式更改它),都会阻止 Ajax 调用。详细解释见IFRAME sandbox attribute is blocking AJAX calls

    【讨论】:

    • 这有助于理解,但我已将其设置为使用 CORS。我可以在用户单击提交之前调用我的 API 以记录各种内容,而不是使用提交按钮/操作。
    • @MarcusCollins 对它的工作感到惊讶,因为您的 ajax 调用在沙盒 iFrame 内运行,并且根据stackoverflow.com/questions/14486461/…,它不会工作。您是说只需在 API 上启用 CORS,您就可以从沙盒 iFrame 内部调用它吗?请注意,您的自定义 UI 模板仅在“真实”场景中在沙盒 iFrame 中运行(预览 UI 时,它不会在沙盒 iFrame 中呈现)
    【解决方案2】:

    这个例子可能会有所帮助。

    它更新了 onSubmit 函数以进行一些预提交验证。

    https://github.com/aws-samples/amazon-sagemaker-ground-truth-task-uis/blob/master/images/keypoint-additional-answer-validation.liquid.html

    希望这会有所帮助。如果没有,请告诉我们。

    谢谢,

    亚马逊机械土耳其人

    【讨论】:

    • 抱歉,这不起作用。我什至不确定它与我已经在做的事情有什么不同......
    猜你喜欢
    • 2021-06-12
    • 2020-10-06
    • 2012-01-24
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    相关资源
    最近更新 更多