Giter Club home page Giter Club logo

Comments (6)

Anthropic avatar Anthropic commented on August 19, 2024 2

@brianpkelley I'm on holiday this week but I will try to add this change next week, thanks for taking the time to provide the info! :)

from angular-schema-form-material.

brianpkelley avatar brianpkelley commented on August 19, 2024 1

md-datepicker returns a Date object, and angular-schema-form wants a string. Without calling one of the toString methods on it, it won't matter what we pass to it.

How I fixed it was:
Add this conditional to the /angular-schema-form/src/services/validator.js around line 39

    // Date values
    if ( schema.type === 'string' && schema.format === 'date' ) {
        if ( value === null ) {
            value = undefined;
        } else {
            if ( typeof value.toISOString === 'function' ) {
                value = value.toISOString();
            }
        }
    }

from angular-schema-form-material.

brianpkelley avatar brianpkelley commented on August 19, 2024 1

In testing found a bug in the date check, I've updated my comment above to reflect the change.

from angular-schema-form-material.

juanmav avatar juanmav commented on August 19, 2024

@brianpkelley Great! Thanks! I will try it!

from angular-schema-form-material.

brianpkelley avatar brianpkelley commented on August 19, 2024

The fix above only works dates outside of arrays (i'd say average operation) if they're inside of an array type tv4 is handling the validation and we can't convert the angular <input type="date" directive which is passing back a Date object.

To fix this, I hackishly created another date format/builder with "type": "object" and "format": "date" and applied the tv4 custom format to validate the date. This way tv4 is looking for an object (check) and the custom format validates it.

    // ISO Format - 2016-08-02T17:03:18.608Z - new Date().toISOString()
    var dateFormat = /^[0-9]{4,}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+|)(?:[+-][0-9]{2}:?(?:[0-9]{2}|)|Z)$/;
    // Standard Format - Tue Aug 02 2016 12:03:59 GMT-0500 (CDT) - new Date().toString()
    var mdDateFormat = /^(:?[A-Z][a-z]{2}\s){2}\d{1,2}\s\d{4}\s(:?\d{2}\:?){3}\s[A-Z]{3}\-\d{4}\s\([A-Z]{3}\)$/;

    var formats = {
        date: function (value) {
            if ( value && typeof value !== 'string' && value.toISOString ) {
                value = value.toISOString() || '';
            }

            if (dateFormat.test(value) || mdDateFormat.test(value) ) {
                return null;
            }

            return 'A valid date expected';
        }
    };
    tv4.addFormat( 'date', formats.date );

    function dateObjectDefault(name, schema, options) {
      if (schema.type === 'object' && (schema.format === 'date' || schema.format === 'date-time')) {
        var f = schemaFormProvider.stdFormObj(name, schema, options);
        f.key  = options.path;
        f.type = 'date';
        options.lookup[sfPathProvider.stringify(options.path)] = f;
        return f;
      }
    };

    schemaFormProvider.defaults.object.unshift(dateObjectDefault);

from angular-schema-form-material.

hugoalexmartins avatar hugoalexmartins commented on August 19, 2024

@brianpkelley hey I am facing a same problem with datepicker.

After place the code above in material-decorator.js, build, and also changed the type object. I did well ?

Because if a use the datepicker and chose a date seems to be fine, but if a have the field required and don't chose any date I just received "Invalid type, expected object", so do I need to change the validator.js also ?

I appreciate any help.

from angular-schema-form-material.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.