Code Monkey home page Code Monkey logo

Comments (3)

hamzahamidi avatar hamzahamidi commented on July 18, 2024

Thank you for using the library. Can you please post the json schema you used to reproduce the issue?

from ajsf.

koczkadavid avatar koczkadavid commented on July 18, 2024

It was the Hack: Conditions one from the examle.
Also, can you please provide some info on how to work with the conditions? I've tried to pass a boolean from any source, in string or standard bool format, but none of them worked, apart from the boolean toggles from the schema itself.

https://hamidihamza.com/Angular6-json-schema-form/?set=asf&example=asf-hack-conditional-required&framework=material-design&language=en

from ajsf.

hamzahamidi avatar hamzahamidi commented on July 18, 2024
{
  "schema": {
    "type": "object",
    "properties": {
      "commentary": {
        "title": "commentary",
        "type": "string",
      },
      "depCommentary": {
        "title": "dependant commentary",
        "type": "integer"
      },
    "notDisplayedcommentary": {
        "title": "this commentary will not be displayed no matter what",
        "type": "string",
      },
    },
    "required": [
    ]
  },
  "form": [
    {
      "type": "help",
      "helpvalue": "<p>This is a work around to use conditions in <b>angular6-json-schema-form</b>. </br> Schema Form does not support oneOf (yet), but you can do a workaround and simulate certain scenarios with 'condition' and 'required'  (and/or 'readonly') in the form.</p>"
    },
    "commentary",
    {
      "key": "depCommentary",
      "condition": "model.commentary",
      "required": true
    },
    {
      "key": "depCommentary",
      "condition": "!model.commentary"
    },
    {
      "type": "submit",
      "style": "btn-info",
      "title": "OK"
    }
  ]
}

This is only a workaround & doesn't abide by the rules of the Json schema drafts. You still need to use the object "form", where you need to specify the content of you HTML form.

In the example above you can see I added the key "commentary". This means that the field "commentary" will be displayed by default.

"notDisplayedcommentary" will not be displayed because it doesn't exist in the "form" object.

As for "depCommentary", it will display but depending on the condition if "commentary" is not undefined.

from ajsf.

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.