danielo515 / obsidian-modal-form

Define forms for filling data that you will be able to open from anywhere you can run JS
https://danielorodriguez.com/obsidian-modal-form/
MIT License
211 stars 18 forks source link

[Feature request] Ability to have default boolean as 'null', and conditional check for said 'null' state #306

Open theodeyle opened 3 months ago

theodeyle commented 3 months ago

Is your feature request related to a problem? Please describe. When I have a conditional set upon another field that is itself a conditional, it will be displayed even though the value it is dependent on is not shown.

An example is in the following form, the role_change_date is dependent on the offboard_flag being false, and the offboard_flag is dependent on the replacement_flag being true. But when the replacement_flag is false, the role_change_date field will show.

{
  "title": "Onboard New User",
  "name": "getNewUser",
  "fields": [
    {
      "name": "user_name",
      "label": "User Name",
      "description": "",
      "isRequired": true,
      "input": {
        "type": "text"
      }
    },
    {
      "name": "user_role",
      "label": "Role",
      "description": "",
      "isRequired": true,
      "input": {
        "type": "note",
        "folder": "2 - Areas/Work/Roles"
      }
    },
    {
      "name": "start_date",
      "label": "Start Date",
      "description": "",
      "isRequired": false,
      "input": {
        "type": "date"
      }
    },
    {
      "name": "location",
      "label": "Location",
      "description": "",
      "isRequired": true,
      "input": {
        "type": "note",
        "folder": "2 - Areas/Work/Groups/Locations"
      }
    },
    {
      "name": "replacement_flag",
      "label": "Replacement?",
      "description": "",
      "isRequired": false,
      "input": {
        "type": "toggle"
      }
    },
    {
      "name": "current_user",
      "label": "Current User",
      "description": "",
      "isRequired": false,
      "condition": {
        "dependencyName": "replacement_flag",
        "type": "boolean",
        "value": true
      },
      "input": {
        "type": "select",
        "source": "notes",
        "folder": "2 - Areas/Work/People/Users/Active",
        "options": []
      }
    },
    {
      "name": "offboard_flag",
      "label": "Offboarding?",
      "description": "",
      "isRequired": false,
      "condition": {
        "dependencyName": "replacement_flag",
        "type": "boolean",
        "value": true
      },
      "input": {
        "type": "toggle"
      }
    },
    {
      "name": "offboarding_date",
      "label": "Offboarding Date",
      "description": "Date the user will be offboarded",
      "input": {
        "type": "date",
        "allowUnknownValues": false
      },
      "condition": {
        "dependencyName": "offboard_flag",
        "type": "boolean",
        "value": true
      },
      "isRequired": false
    },
    {
      "name": "role_change_date",
      "label": "Role Change Date",
      "description": "",
      "input": {
        "type": "date",
        "allowUnknownValues": false
      },
      "condition": {
        "dependencyName": "offboard_flag",
        "type": "boolean",
        "value": false
      },
      "isRequired": false
    }
  ],
  "version": "1",
  "template": {
    "createCommand": true,
    "parsedTemplate": []
  }
}

Describe the solution you'd like It would be preferred if there was a third state of null/not set, etc., so that it could be checked in conditionals further down the list.

Additional context Note "Role Change Date" field displayed, despite the Replacement flag being set to false. If toggles could be null, and conditionals could be checked for it, this would be remedied.

image

danielo515 commented 3 months ago

The problem here is that boolean/toggles are always set to a value. This was to overcome a limitation that I can't recall right now, but it was there for a reason. I have to review why