Gilbert Nwaiwu
Gilbert Nwaiwu

Reputation: 728

Aurelia: Custom Elements vs Custom Attributes

I would like to know what's the difference between using custom elements or custom attributes in Aurelia.

I am using a datepicker from jqueryUI. I implemented it as a custom attribute(following this https://www.danyow.net/jquery-ui-datepicker-with-aurelia/) and it works perfectly. I wasn't able to make it into a custom element tough. I looked around and found some examples online but they didn't work.

I want to know if there are any disadvantages to using custom attributes in place of custom elements.

Upvotes: 2

Views: 318

Answers (1)

kabaehr
kabaehr

Reputation: 1040

A custom attribute is for extending the functionality of an existing HTML Element and actually have no view. Like in your example you want to extend the functionality of an input field. It shall look like an input, have standard focus/form/validation etc. input behaviour and so on ( if <input type="date"/> would be proper implemented in all browser we would surely use this instead of jquery-datepicker ).

custom elements are a possibility to write your own reusable element inclusive an own view and own functionality and logic.

Examples:

custom element

  • self made datepicker (need to show some dates and so on = view)
  • own autocomplete input (you will need view for showing a list)
  • recurring ui-elements (e.g. a data, image pair where the image shall always on the left side and do something on click, 5 lines html and logic wrapped in one custom element)

custom attribute

  • use a 3rd party Datepicker (like jQuery-ui, which will just do a jQuery call to add a view programatically)
  • use google maps places autocomplete (just an api call which will change the input value and show dynamically added view, no own view)
  • an image which shall have special behaviour ( like a image which will make a rest call and change the image)

Upvotes: 6

Related Questions