Aurelia Custom Element for modal form

LStarky

Simplified GistRun: https://gist.run/?id=e87e5664097f20a2950c4d0aa5bf1977

I'm trying to create a custom element in Aurelia to build a modal form container, as follows. However, the page is not loading. If I remove all of the ${} tags, it loads. Why is the binding for the custom element not working correctly? It seems like the problems are in the ref=${name_ref}, if.bind="${record_id}" and similar bindings. I'm able to display the values of all of the binded values as page content.

Also, even if I hardcode the ref of the custom element (ref="edit_division"), I still can't reference it from my parent JavaScript. I should be able to use $(this.edit_division).modal(); to open the modal, but it's not linking the ref.

Finally, the click.delegate="closeModal()" is not finding the function in the parent JavaScript.

modal-form.html

<template>

  <!-- Modal edit window -->
  <div class="modal fade" ref="${name_ref}" tabindex="-1" role="dialog" aria-labelledby="Edit Division">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header modal-header-success">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title"><span if.bind="${record_id}" t="${label_edit}"></span><span if.bind="!${record_id}" t="${label_new}"></span></h4>
        </div>
        <div class="modal-body">
        <div class="alert alert-danger" if.bind="error">${error&t}</div>

        <slot><!-- Custom element inner content will be inserted here --></slot>

        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-danger pull-left" click.delegate="deleteRecord()" if.bind="${record_id}" tabindex=99><span t="Delete"></span></button>
          <button type="button" class="btn btn-secondary" click.delegate="closeModal()"><span t="Cancel"></span></button>
          <button type="button" class="btn btn-primary" click.delegate="saveRecord()"><span t="Save"></span></button>
        </div>
      </div>
    </div>
  </div>

</template>

modal-form.js

import { bindable } from 'aurelia-framework';

export class ModalFormCustomElement {

  @bindable name_ref;
  @bindable record_id;
  @bindable label_new;
  @bindable label_edit;
  @bindable error;

}

Implementation:

<modal-form name_ref="edit_division" record_id="division.div_id" label_new="New_Division" label_edit="Edit_Division">

  <form>
    <div class="form-group">
      <label class="control-label" for="div_code"><span t="Division_code"></span></label>
      <input type="text" class="form-control" ref="div_code" value.bind="division.div_code & validate" />
    </div>
    <div class="form-group">
      <label class="control-label" for="div_name"><span t="Division_name"></span></label>
      <input type="text" class="form-control" value.bind="division.div_name & validate">
    </div>
    <div class="form-group">
      <label class="control-label" for="div_principal_p_id"><span t="Principal"></span></label>
      <input type="text" class="form-control" value.bind="division.div_principal_p_id">
    </div>
  </form>

</modal-form>
LStarky

In case anyone is looking at this question later, I updated the GistRun with a working modal dialog via a custom element. Hopefully it can be helpful for someone else in the future!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Aurelia: validating form with reusable validatable custom element

From Dev

Aurelia: validating form with reusable validatable custom element

From Dev

Custom Element Singletons in Aurelia

From Dev

Aurelia Custom element with dialog

From Dev

Aurelia Multiple Properties in custom element

From Dev

Aurelia - render custom element by name

From Dev

Aurelia: Binding textContent of a custom element?

From Dev

Aurelia custom element with a table with a slot in it

From Dev

Binding to a Custom Element in a Template Part in Aurelia

From Dev

How to render razor view in aurelia custom element?

From Dev

Aurelia bindable attribute with HTML only custom element

From Dev

Custom Delegate with Modal Form Sheet not working

From Dev

What is the difference between custom element and just an import using require in Aurelia

From Dev

Two-way binding between parent and child custom element in Aurelia

From Dev

Aurelia two-way binding in custom element not working

From Dev

How to set a parent property from within a custom element in Aurelia?

From Dev

How to implement bootstrap-datepicker as Aurelia custom element

From Dev

Aurelia - Inline definition of HTML-only custom element

From Dev

Aurelia binding hook on "nested" data update in custom element

From Dev

What is the difference between custom element and just an import using require in Aurelia

From Dev

Aurelia two-way binding in custom element not working

From Dev

Possible in Aurelia to wait for a promise in a custom element to complete before execution continues?

From Dev

How to reference specific elements in Aurelia custom element's <slot>?

From Dev

Replace Custom Element with template itself (rather than including it inside the custom element) in Aurelia?

From Dev

symfony 2 create custom form how to get form custom element?

From Dev

Adding Drupal Field Collection element to a custom form

From Dev

ZF2 - Register custom form element

From Dev

Drupal custom registration Form element not showing on frontend

From Dev

Mapping Play Framework form element to custom type

Related Related

  1. 1

    Aurelia: validating form with reusable validatable custom element

  2. 2

    Aurelia: validating form with reusable validatable custom element

  3. 3

    Custom Element Singletons in Aurelia

  4. 4

    Aurelia Custom element with dialog

  5. 5

    Aurelia Multiple Properties in custom element

  6. 6

    Aurelia - render custom element by name

  7. 7

    Aurelia: Binding textContent of a custom element?

  8. 8

    Aurelia custom element with a table with a slot in it

  9. 9

    Binding to a Custom Element in a Template Part in Aurelia

  10. 10

    How to render razor view in aurelia custom element?

  11. 11

    Aurelia bindable attribute with HTML only custom element

  12. 12

    Custom Delegate with Modal Form Sheet not working

  13. 13

    What is the difference between custom element and just an import using require in Aurelia

  14. 14

    Two-way binding between parent and child custom element in Aurelia

  15. 15

    Aurelia two-way binding in custom element not working

  16. 16

    How to set a parent property from within a custom element in Aurelia?

  17. 17

    How to implement bootstrap-datepicker as Aurelia custom element

  18. 18

    Aurelia - Inline definition of HTML-only custom element

  19. 19

    Aurelia binding hook on "nested" data update in custom element

  20. 20

    What is the difference between custom element and just an import using require in Aurelia

  21. 21

    Aurelia two-way binding in custom element not working

  22. 22

    Possible in Aurelia to wait for a promise in a custom element to complete before execution continues?

  23. 23

    How to reference specific elements in Aurelia custom element's <slot>?

  24. 24

    Replace Custom Element with template itself (rather than including it inside the custom element) in Aurelia?

  25. 25

    symfony 2 create custom form how to get form custom element?

  26. 26

    Adding Drupal Field Collection element to a custom form

  27. 27

    ZF2 - Register custom form element

  28. 28

    Drupal custom registration Form element not showing on frontend

  29. 29

    Mapping Play Framework form element to custom type

HotTag

Archive