Skip to content

new: new field 'input' #70

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

Merged
merged 6 commits into from
Sep 20, 2016
Merged

Conversation

lionel-bijaoui
Copy link
Member

#50 this is my proposal for this fields.

The test are not amazing for now (they accept any attribute regardless of the input type).

@lionel-bijaoui lionel-bijaoui mentioned this pull request Sep 14, 2016
13 tasks
@icebob
Copy link
Member

icebob commented Sep 14, 2016

Thank you for your PR. I need more time to check it, ok?

Copy link
Member

@icebob icebob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the type to input instead of html5

@icebob icebob changed the title new: new field html5 input new: new field 'input' Sep 14, 2016
@icebob icebob added this to the v0.5.0 milestone Sep 14, 2016
@icebob
Copy link
Member

icebob commented Sep 15, 2016

I think, we can't handle all types with one field. Because for date* types there are extra properties and methods to format date to the input and to the model like here

Do you have any idea how to solve it?

@lionel-bijaoui
Copy link
Member Author

A simple check to see the this.schema.format could be enough:

if (typeof this.schema.format !== "undefined" && value != null) {
    return moment(value, this.schema.format).format(this.getDateFormat());
}
return value;

If the user don't want to format the date or if there is no reason to use format (for non date like input), it simply return the raw value.

@icebob
Copy link
Member

icebob commented Sep 16, 2016

Not enough, because current date fields (datePicker, pickaday) are stored the data in Unix format without format. If you set format property it will store as a formatted date string. But HTML5 date* field raw format is string. So we always should format this raw values.

I created a fiddle to check the raw values of HTML5 date fields: https://jsfiddle.net/ndz05ku4/2/

@lionel-bijaoui
Copy link
Member Author

What about using inputType ?

if (value != null) {
    if (this.schema.inputType === date ||
        this.schema.inputType === datetime ||
        this.schema.inputType === datetimelocal ||
        this.schema.inputType === time ||
        this.schema.inputType === week ||
        this.schema.inputType === month) {
            if (typeof this.schema.format === "undefined"){
                // Unix formating
            }else{
                return moment(value, this.schema.format).format(this.getDateFormat());
            }
    }
}
return value;

@icebob
Copy link
Member

icebob commented Sep 16, 2016

Ok, but skip month and week. They are not full date, can't be format with moment. Stays in string.

@lionel-bijaoui
Copy link
Member Author

lionel-bijaoui commented Sep 19, 2016

I'm skipping time too.

@icebob can you validate this ?

field value to field value to model
date yyyy-MM-dd UNIX
datetime yyyy-MM-ddThh:mm UNIX
datetimelocal yyyy-MM-ddThh:mm UNIX
time hh:mm hh:mm
week String String
month String String

@lionel-bijaoui
Copy link
Member Author

lionel-bijaoui commented Sep 19, 2016

Progress: date, datetime and datetime-local can use the same model as pikaday, dateTime (with date format) without problem. Modifying one or the other end in the same model format (UNIX) and update value.
time work well with dateTime (with time format), although Chrome don't allow to input/modify seconds (but display them if set) (if step is defined to 1, then it work) . Edge is fine with seconds.
month and week are treated as string.

methods: {
    formatValueToField(value) {
        switch(this.schema.inputType){
            case "date":
                return moment(value).format("YYYY-MM-DD");
            case "datetime":
                return moment(value).format();
            case "datetime-local":
                return moment(value).format("YYYY-MM-DDTHH:mm:ss");
            default:
                return value;
        }
    },
    formatValueToModel(value) {
        console.log(this.schema.inputType, typeof value);
        if (value != null) {
            if (this.schema.inputType === "date" ||
                this.schema.inputType === "datetime" ||
                this.schema.inputType === "datetimelocal") {
                return new Date(value).getTime();
            }else{
                return value;
            }
        } else {
            return value;
        }
    }
}

@icebob
Copy link
Member

icebob commented Sep 19, 2016

Great thank you!

@lionel-bijaoui
Copy link
Member Author

@icebob Can I add a new schema to the commit ?
I have reorganize the fields so that it is easier to use
screenshot

@icebob
Copy link
Member

icebob commented Sep 19, 2016

Sure :)

@lionel-bijaoui
Copy link
Member Author

@icebob I think it is ready to merge, no ?

}
},
formatValueToModel(value) {
console.log(this.schema.inputType, typeof value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this log message and after it I will merge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Copy link
Member Author

@lionel-bijaoui lionel-bijaoui Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to merge, no ? I think you just approved the changes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just waited the green lights :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I did not get it 👍

@icebob icebob merged commit fea94c1 into vue-generators:master Sep 20, 2016
@lionel-bijaoui lionel-bijaoui deleted the LB_html5 branch September 20, 2016 12:52
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

Successfully merging this pull request may close these issues.

2 participants