question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set initial date and don't use the src from release by the moment.

See original GitHub issue

Hi everyone!

How do i set a initial date in a string with date format?

I have tried this in the demo, but no luck, even when setting a proper date for input type date (YYYY-MM-DD) in the initial data like this:

{ date: "2018-1-13" }

Also not working with:

{ date: "2018-01-13T00:00:00" }

With time, it works like this:

{ time: "14:00" }

and schema (minimalist example):

{ "$schema": "http://json-schema.org/draft-03/schema#", "type": "object", "properties": { "time": { "type": "string", "format": "time" } } }

If there is no support, I can work on it.

Thanks in advance!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
juamarcommented, Jan 29, 2018

Eureka, I 've done it! i have modified the lines regarding the value set in brutusin-json-forms.js.

if (value !== null && typeof value !== "undefined") {
                if (s.format === "date")
                {
                    try
                    {
                        var date = new Date(value);
                        //console.log(date);

                        var year = date.getFullYear(); // This will work as long as year is 1000 or bigger.
                        var month = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
                        var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();

                        input.value = year + "-" + month + "-" + day;
                        //console.log(input.value);
                    }
                    catch(err)
                    {
                        console.warn("The date is not valid");
                        input.value = value;
                    }
                }
                else
                {
                    input.value = value;
                }

                // readOnly?
                if (s.readOnly)
                    input.disabled = true;

            }

(I did my best with the formatting, but i don’t know what is going on).

It will be nice to commit it to master. I tried to make a pull request, but it seems i got to create a new branch, but the interface here is not letting me (maybe using git on a local machine?). Maybe if you help me out, we can get it done.

Thanks!

1reaction
juamarcommented, Jan 10, 2018

When setting BrutusinForms.bootstrap.addFormatDecorator(“date”, “date”) before BrutusinForms.create(schema), when form is loaded, form will override the value for the input with date decorator. I will study it to learn how to keep our decorator with our date picker.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Moment.js transform to date object - javascript - Stack Overflow
Use this to transform a moment object into a date object: From http://momentjs.com/docs/#/displaying/as-javascript-date/ moment().toDate();. Yields:
Read more >
Working with Moment.js Date Libraries - Section.io
Moment.js is the tool every JavaScript developer wants to use to achieve date and time object with simplicity.
Read more >
Docs - Moment.js
Unlike a Moment object, it can not be set to use another time zone; It has no concept of "mode". Using Date.parse ,...
Read more >
React custom datepicker: Step-by-step - LogRocket Blog
First, we'll verify the formatting of the date in the calendar module by appending the following code to the src/helpers/calendar.js file:
Read more >
The Picture element - HTML: HyperText Markup Language
If providing higher-density versions of an image for high-DPI (Retina) display, use srcset on the <img> element instead. This lets browsers opt ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found