Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL param with type date and default value null breaks #3816

Open
1 of 3 tasks
pblanchardie opened this issue Jul 27, 2020 · 3 comments
Open
1 of 3 tasks

URL param with type date and default value null breaks #3816

pblanchardie opened this issue Jul 27, 2020 · 3 comments

Comments

@pblanchardie
Copy link

pblanchardie commented Jul 27, 2020

This is a (check one box):

  • 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 )

@stale
Copy link

stale bot commented Jun 11, 2021

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 stale bot added stale and removed stale labels Jun 11, 2021
@stale
Copy link

stale bot commented Apr 18, 2022

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 stale bot added the stale label Apr 18, 2022
@exglade
Copy link

exglade commented Jul 26, 2022

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
    }
  }
});

@stale stale bot removed the stale label Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants