Skip to content

docs: How can we read textFormField value. #222

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

Open
dhirajReliance opened this issue Apr 23, 2025 · 5 comments
Open

docs: How can we read textFormField value. #222

dhirajReliance opened this issue Apr 23, 2025 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@dhirajReliance
Copy link

Description

There is no documentation available to read fields value. I did not found the same if documentation is available please share otherwise please guid me how can i read form value.
Here is my json-----

{

"type": "scaffold",
"backgroundColor": "#F4F6FA",
"appBar": {
"type": "appBar",
"backgroundColor": "#00FFFFFF"
},
"body": {
"type": "form",
"id": "login_form",
"child": {
"type": "padding",
"padding": {"left": 24, "right": 24},
"child": {
"type": "column",
"crossAxisAlignment": "start",
"children": [
{
"type": "text",
"data": "Sign in",
"style": {"fontSize": 24, "fontWeight": "w800", "height": 1.3}
},

      {"type": "sizedBox", "height": 24},
      {
        "type": "textFormField",
        "maxLines": 1,
        "id": "email",
        "controller": "emailController",
        "autovalidateMode": "onUserInteraction",
        "validatorRules": [
          {
            "rule": "isEmail",
            "message": "Please enter a valid email"
          }
        ],
        "style": {"fontSize": 16, "fontWeight": "w400", "height": 1.5},
        "decoration": {
          "hintText": "Email",
          "filled": true,
          "fillColor": "#FFFFFF",
          "border": {
            "type": "outlineInputBorder",
            "borderRadius": 8,
            "color": "#24151D29"
          }
        }
      },
      {"type": "sizedBox", "height": 16},
      {
        "type": "textFormField",
        "id": "password",
        "autovalidateMode": "onUserInteraction",
        "validatorRules": [
          {"rule": "isPassword", "message": "Please enter a valid password"}
        ],
        "controller": "passwordController",
        "obscureText": true,
        "maxLines": 1,
        "style": {"fontSize": 16, "fontWeight": "w400", "height": 1.5},
        "decoration": {
          "hintText": "Password",
          "filled": true,
          "fillColor": "#FFFFFF",
          "border": {
            "type": "outlineInputBorder",
            "borderRadius": 8,
            "color": "#24151D29"
          }
        }
      },
      {"type": "sizedBox", "height": 24},

      {
        "type": "filledButton",
        "style": {
          "backgroundColor": "#151D29",
          "shape": {"borderRadius": 8}
        },
        "onPressed": {
          "actionType": "customNavigate",
          "target": "login_screen"
        },
        "child": {
          "type": "padding",
          "padding": {"top": 14, "bottom": 14, "left": 16, "right": 16},
          "child": {
            "type": "row",
            "mainAxisAlignment": "spaceBetween",
            "children": [
              {"type": "text", "data": "Proceed",  "style": {"fontSize": 16, "fontWeight": "w400", "height": 1.5}},
              {
                "type": "icon",
                "iconType": "material",
                "icon": "arrow_forward"
              }
            ]
          }
        }
      },
      {"type": "sizedBox", "height": 16},
      {
        "type": "align",
        "alignment": "center",
        "child": {
          "onPressed": {
            "actionType": "customNavigate",
            "target": "forgot_screen"
          },
          "type": "textButton",

          "child": {
            "type": "text",
            "data": "Forgot password?",
            "style": {
              "fontSize": 15,
              "fontWeight": "w500",
              "color": "#4745B4"
            }
          }
        }
      },
      {"type": "sizedBox", "height": 8},
      {
        "type": "align",
        "alignment": "center",
        "child": {
          "type": "text",
          "data": "Don't have an account? ",
          "style": {
            "fontSize": 15,
            "fontWeight": "w400",
            "color": "#000000"
          },
          "children": [
            {
              "data": "Sign Up for BettrDo",
              "style": {
                "fontSize": 15,
                "fontWeight": "w500",
                "color": "#4745B4"
              }
            }
          ]
        }
      }
    ]
  }
}

}
}

@dhirajReliance dhirajReliance added the documentation Improvements or additions to documentation label Apr 23, 2025
@divyanshub024
Copy link
Member

divyanshub024 commented Apr 24, 2025

Hey @dhirajReliance, you can use the getFormValue action to read the textFormField values.

{
  "onPressed": {
    "actionType": "validateForm",
    "isValid": {
      "actionType": "networkRequest",
      "url": "https://dummyjson.com/users/add",
      "method": "post",
      "headers": {
        "Content-Type": "application/json"
      },
      "body": {
        "firstName": {
          "actionType": "getFormValue",
          "id": "firstName"
        },
        "lastName": {
          "actionType": "getFormValue",
          "id": "lastName"
        },
        "email": {
          "actionType": "getFormValue",
          "id": "email"
        },
        "phoneNumber": {
          "actionType": "getFormValue",
          "id": "phoneNumber"
        }
      }
    }
  }
}

For more details check out our blog on Forms -> https://stac.dev/blog/dynamic-form

@dhirajReliance
Copy link
Author

Hi @divyanshub024 I do not want to handle API calls in this way. Let me explain how I want to implement it in my project.

I want Stac only for design purpose & I want to implement business logic in my project codebase itself. So to do that i have get values form textFormField & or other widgets and set value in json text if it require.
Could you please let me know this type of customisation is possible or not we are ok to pay if it is chargeable.
Hoping quick reply so that we can adopt this in my project which we are going to start in 1st week of May.

@dhirajReliance
Copy link
Author

dhirajReliance commented Apr 25, 2025

I want to implement something like this---
/// Custom action parser that handles "navigate" actionType
class NavigateActionParser extends StacActionParser {
final GlobalKey formKey= GlobalKey();

@OverRide
String get actionType => 'customNavigate';

@OverRide
NavigateActionModel getModel(Map<String, dynamic> json) {
return NavigateActionModel(target: json['target']);
}

@OverRide
Future onCall(BuildContext context, NavigateActionModel model) async {

debugPrint('Email--- ${email}');
debugPrint('Password--- $password');

if(formKey.currentState?.validate() ?? false) {
  Get.toNamed('/${model.target}');
}

}
}

@divyanshub024
Copy link
Member

Hey @dhirajReliance, I would love to jump on a call with you to understand it better. I think we can add this feature as a priority for you. Please send me an email at divyanshub024@gmail.com, and I'll set up a meeting.

@dhirajReliance
Copy link
Author

Hey @dhirajReliance, I would love to jump on a call with you to understand it better. I think we can add this feature as a priority for you. Please send me an email at divyanshub024@gmail.com, and I'll set up a meeting.

Sent mail please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants