I have the following core-elements dropdown element in which I used paper-item instead of core-item to display the dropdown label.
// .html
<input required
id='birthday'
name='birthday'
type='date'
value="{{age.birthday}}"
on-change='{{inputHandler}}'>
<div layout horizontal>
<div layout vertical self-center
id='years-div'>Years
<core-dropdown disabled
id='years-core-ddwn'
halign="left"
label='0'
valueattr="label">
<template repeat="{{year in yearsList}}">
<paper-item id='years-ppr-itm' label="{{year}}"></paper-item>
</template>
</core-dropdown>
</div>
//.dart
var yearsList = <int>[ 1, 2, 3, 4]
@observable int year = 0;
class Age
{
int years = 0;
String birthday = '';
}
// calcualate age in years
void inputHandler()
{
if ( age.birthday != '' )
{
DateTime now = new DateTime.now();
DateTime birthday = DateTime.parse( age.birthday.replaceAll( r'-', '') );
//Duration dayz = ( birthday.difference( new DateTime.now() ) ).inDays;
Duration duration = new DateTime.now().difference( birthday );
// calculate years since birth
int days = duration.inDays;
age.years = days ~/ 365;
// attempting to set the PaperItem label to the calculated age
yearsPprItm = $[ 'years-ppr-itm' ] as PaperItem;
// neither of the following resets the PaperItem label to the age variable
yearsPprItm.setAttribute( 'label', age.years.toString() );
//year = age.years.toString();
}
The drop-down displays normally and selected item is retrieved normally also.
There are no error stack trace, yet the paper-item label is not changed using setAttribute or assigning the age.years to the observable year to which the label is bound.
I am wondering if it is illegal to bind to and iterator variable. If so, what is the correct method of accomplishing what I am trying to do.
Thanks