{"id":32418303,"url":"https://github.com/drualcman/editformdemo.validation","last_synced_at":"2026-05-18T04:10:56.105Z","repository":{"id":181581988,"uuid":"666990035","full_name":"drualcman/EditFormDemo.Validation","owner":"drualcman","description":"Manual validation in Blazor EditForm component","archived":false,"fork":false,"pushed_at":"2025-05-25T03:42:04.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-06T09:55:54.213Z","etag":null,"topics":["blazor","blazor-server","blazor-webassembly"],"latest_commit_sha":null,"homepage":"https://aprende-a-programar.com/b/Como-validar-un-formulario-manualmente-en-Blazor-Server-o-WebAssembly/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drualcman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-07-16T09:14:09.000Z","updated_at":"2025-05-25T03:42:07.000Z","dependencies_parsed_at":"2023-07-16T10:48:04.662Z","dependency_job_id":null,"html_url":"https://github.com/drualcman/EditFormDemo.Validation","commit_stats":null,"previous_names":["drualcman/editformdemo.validation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drualcman/EditFormDemo.Validation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drualcman%2FEditFormDemo.Validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drualcman%2FEditFormDemo.Validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drualcman%2FEditFormDemo.Validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drualcman%2FEditFormDemo.Validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drualcman","download_url":"https://codeload.github.com/drualcman/EditFormDemo.Validation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drualcman%2FEditFormDemo.Validation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280987564,"owners_count":26425343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blazor","blazor-server","blazor-webassembly"],"created_at":"2025-10-25T16:52:45.199Z","updated_at":"2026-05-18T04:10:56.098Z","avatar_url":"https://github.com/drualcman.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Manual validation EditForm Component Demo\nThis project it�s a simple example how to validate a model when you don�t have access to the model code.\n\n## Scenario\n* The class ```ExampleModelFromExternalDll``` represent a exterdal model we can't modify.\n* We will manually validate some properties\n* Must be show a validation error messages\n* When is validated can send the form\n\n### Example \nComponent\n``` RAZOR\n    \u003cEditForm EditContext=FormContext OnValidSubmit=SubmitForm\u003e\n        \u003cdiv class=\"field\"\u003e\n            \u003clabel class=\"label\"\u003eFirst Name\u003c/label\u003e\n            \u003cdiv class=\"control\"\u003e\n                \u003cInputText @bind-Value=Model.FirstName class=\"input\" /\u003e\n                \u003cValidationMessage For=\"() =\u003e Model.FirstName\" /\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n        \u003cdiv class=\"field\"\u003e\n            \u003clabel class=\"label\"\u003eEmail\u003c/label\u003e\n            \u003cdiv class=\"control\"\u003e\n                \u003cInputText @bind-Value=Model.Email class=\"input\" type=\"email\" /\u003e\n                \u003cValidationMessage For=\"() =\u003e Model.Email\" /\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e    \n        \u003cdiv class=\"field\"\u003e\n            \u003cdiv class=\"control\"\u003e\n                \u003cbutton class=\"button is-success\"\u003eSubmit\u003c/button\u003e\n            \u003c/div\u003e\n            \u003clabel class=\"label\"\u003e@Messages\u003c/label\u003e\n        \u003c/div\u003e\n    \u003c/EditForm\u003e\n```\nCode\n``` CSHARP\nstring Messages;\n    ExampleModelFromExternalDll Model = new();\n    EditContext FormContext;\n    ValidationMessageStore ValidationMessageStore;\n\n    protected override void OnInitialized() \n    {\n        FormContext = new EditContext(Model);\n        FormContext.OnFieldChanged += FormContext_OnFieldChanged;\n        FormContext.OnValidationRequested += FormContext_OnValidationRequested;\n        ValidationMessageStore = new ValidationMessageStore(FormContext);\n    }\n\n    private void FormContext_OnValidationRequested(object sender, ValidationRequestedEventArgs e) \n    {\n        Messages = \"\";\n        ValidationMessageStore.Clear();        \n        if(string.IsNullOrWhiteSpace(Model.FirstName))\n            ValidationMessageStore.Add(new FieldIdentifier(Model, nameof(Model.FirstName)), \"First name required\");\n        if(string.IsNullOrWhiteSpace(Model.Email))\n            ValidationMessageStore.Add(new FieldIdentifier(Model, nameof(Model.Email)), \"Email required\");\n        FormContext.NotifyValidationStateChanged();\n    }\n\n    private void FormContext_OnFieldChanged(object sender, FieldChangedEventArgs e) \n    {      \n        Messages = \"\";\n        ValidationMessageStore.Clear(e.FieldIdentifier);\n        switch(e.FieldIdentifier.FieldName)\n        {\n            case nameof(Model.FirstName):\n                if(string.IsNullOrWhiteSpace(Model.FirstName))\n                    ValidationMessageStore.Add(e.FieldIdentifier, \"First name required\");\n                break;\n            case nameof(Model.Email):\n                if(string.IsNullOrWhiteSpace(Model.Email))\n                    ValidationMessageStore.Add(e.FieldIdentifier, \"Email required\");  \n                if(!Model.Email.Contains(\"@\"))\n                    ValidationMessageStore.Add(e.FieldIdentifier, \"Email not valid\");\n                break;\n        }\n        FormContext.NotifyValidationStateChanged();\n    }\n\n    void SubmitForm()\n    {\n        Messages = \"Form will be send!\";\n    }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrualcman%2Feditformdemo.validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrualcman%2Feditformdemo.validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrualcman%2Feditformdemo.validation/lists"}