ui-router icon indicating copy to clipboard operation
ui-router copied to clipboard

URL param with type date and default value null breaks

Open pblanchardie opened this issue 3 years ago • 3 comments

This is a (check one box):

  • [X] Bug Report
  • [ ] Feature Request
  • [ ] General Query

My version of UI-Router is: (type version)

1.0.27

Bug Report

Current Behavior:

A URL param declaration with type: 'date' and default value: null throws: Cannot read property 'getFullYear' of null

Expected Behavior:

It should work and set null as default value for this param

Link to Plunker or stackblitz that reproduces the issue:

( if you want a response to your issue, provide a way to reproduce it ) ( http://bit.ly/UIR-Plunk1 ) ( https://stackblitz.com/edit/ui-router-angularjs )

pblanchardie avatar Jul 27 '20 14:07 pblanchardie

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions.

stale[bot] avatar Jun 11 '21 01:06 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions.

stale[bot] avatar Apr 18 '22 19:04 stale[bot]

I'm getting the same error message with the same setup. The workaround I'm using is to use undefined instead.

$stateProvider.state('page', {
  url: '/page?{somedate:date}',
  templateUrl: './page.html',
  dynamic: true,
  params: {
    somedate: {
      value: undefined
    }
  }
});

Using undefined, I'm bypassing the Param.prototype.isDefaultValue(value) (param.js) check which calls type.equals(l, r). All types are using simple .equals or == check, but date-type check whether getFullYear(), getMonth(), getDate() are the same values.

The null problem aside, notice that the date-type only check for year, month, date but time component is not checked. So, I think the param type meant specifically date-only, not referring to JavaScript Date object.

Hence, if date-time is involve, best leave it as a string-type, the alternative workaround -- dropping date:

$stateProvider.state('page', {
  url: '/page?somedate',
  templateUrl: './page.html',
  dynamic: true,
  params: {
    somedate: {
      value: undefined
    }
  }
});

exglade avatar Jul 26 '22 09:07 exglade