-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Creating C2T form * Typo fix * Adds section 10 * Adds remaining questions * Validation for section 10 * radio button and validation update * Adds turbo * Add dropdowns to beginning of form * Add dynamic change on modality * progress commit * displays unobtrusive validation on dynamic form change * Add turbo stream to display validation errors * Remove turbo cdn from layout * Remove Mode and RMMode inputs on partial * Adjusts data annotations * Adds javascript file and updates stimulus * Fix for small js bug * Update views and js * Making the linter happy? * Linter round 2 * remove script tags in partials * correct enum dropdown * add custom jquery validation to partials * Add data annotation for telephone/in-person * Update validation * remove rmmode label on C2 * Add/maps missing properties * Using rowCSS variable in views * fix typo * cleaning things up * adds tailwind border around section headers * additional tailwind styling * Add info alert to top of page * Additional validation * Turn off Turbo for participation create * Formatted instructions * Fixes MOCATOS validation * Update dependencies * Bump version number --------- Co-authored-by: Ashley Wilson <[email protected]>
- Loading branch information
Showing
25 changed files
with
3,775 additions
and
1,843 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/UDS.Net.Forms/DataAnnotations/RequiredIfInPersonVisitAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UDS.Net.Forms.Models; | ||
using UDS.Net.Services.Enums; | ||
|
||
namespace UDS.Net.Forms.DataAnnotations | ||
{ | ||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] | ||
public class RequiredIfInPersonVisitAttribute : ValidationAttribute, IClientModelValidator | ||
{ | ||
private string _watchedField = ""; | ||
private string _watchedFieldValue = ""; | ||
|
||
public RequiredIfInPersonVisitAttribute(string watchedField, string value) : base() | ||
{ | ||
_watchedField = watchedField; | ||
_watchedFieldValue = value; | ||
} | ||
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) | ||
{ | ||
// does the form have a status and is it attempting to be finalized? | ||
if (validationContext.ObjectType.IsSubclassOf(typeof(FormModel))) | ||
{ | ||
var form = (FormModel)validationContext.ObjectInstance; | ||
|
||
// only validate if the form is attempting to be completed | ||
if (form.Status == FormStatus.Finalized) | ||
|
||
if (form.MODE == FormMode.InPerson || form.RMMODE == RemoteModality.Video) | ||
{ | ||
// get the watched property and compare | ||
var type = validationContext.ObjectType; | ||
|
||
if (type != null) | ||
{ | ||
var watchedProperty = type.GetProperty(_watchedField); | ||
|
||
if (watchedProperty != null) | ||
{ | ||
var currentValue = watchedProperty.GetValue(validationContext.ObjectInstance, null); | ||
if (currentValue != null) | ||
{ | ||
if (currentValue.ToString() == _watchedFieldValue) | ||
{ | ||
// if the watched field's value matches what we're looking for then this field requires a value | ||
if (value == null) | ||
return new ValidationResult(this.ErrorMessage); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
return ValidationResult.Success; | ||
} | ||
|
||
public void AddValidation(ClientModelValidationContext context) | ||
{ | ||
MergeAttribute(context.Attributes, "data-val", "true"); | ||
MergeAttribute(context.Attributes, "data-val-requiredif", this.ErrorMessage); | ||
string watched = _watchedField; | ||
var containerName = context.ModelMetadata.ContainerType.Name; | ||
if (!String.IsNullOrEmpty(containerName)) | ||
{ | ||
watched = containerName + "." + _watchedField; | ||
} | ||
MergeAttribute(context.Attributes, "data-val-requiredif-watchedfield", watched); | ||
MergeAttribute(context.Attributes, "data-val-requiredif-watchedfieldvalue", _watchedFieldValue); | ||
} | ||
|
||
/// <summary> | ||
/// See https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-7.0#iclientmodelvalidator-for-client-side-validation | ||
/// </summary> | ||
private static bool MergeAttribute(IDictionary<string, string> attributes, string key, string value) | ||
{ | ||
if (attributes.ContainsKey(key)) | ||
{ | ||
return false; | ||
} | ||
|
||
attributes.Add(key, value); | ||
return true; | ||
} | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/UDS.Net.Forms/DataAnnotations/RequiredIfTelephoneVisitAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UDS.Net.Forms.Models; | ||
using UDS.Net.Services.Enums; | ||
|
||
namespace UDS.Net.Forms.DataAnnotations | ||
{ | ||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] | ||
public class RequiredIfTelephoneVisitAttribute : ValidationAttribute, IClientModelValidator | ||
{ | ||
private string _watchedField = ""; | ||
private string _watchedFieldValue = ""; | ||
|
||
public RequiredIfTelephoneVisitAttribute(string watchedField, string value) : base() | ||
{ | ||
_watchedField = watchedField; | ||
_watchedFieldValue = value; | ||
} | ||
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) | ||
{ | ||
// does the form have a status and is it attempting to be finalized? | ||
if (validationContext.ObjectType.IsSubclassOf(typeof(FormModel))) | ||
{ | ||
var form = (FormModel)validationContext.ObjectInstance; | ||
|
||
// only validate if the form is attempting to be completed | ||
if (form.Status == FormStatus.Finalized && form.RMMODE == RemoteModality.Telephone) | ||
{ | ||
// get the watched property and compare | ||
var type = validationContext.ObjectType; | ||
|
||
if (type != null) | ||
{ | ||
var watchedProperty = type.GetProperty(_watchedField); | ||
|
||
if (watchedProperty != null) | ||
{ | ||
var currentValue = watchedProperty.GetValue(validationContext.ObjectInstance, null); | ||
if (currentValue != null) | ||
{ | ||
if (currentValue.ToString() == _watchedFieldValue) | ||
{ | ||
// if the watched field's value matches what we're looking for then this field requires a value | ||
if (value == null) | ||
return new ValidationResult(this.ErrorMessage); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
return ValidationResult.Success; | ||
} | ||
|
||
public void AddValidation(ClientModelValidationContext context) | ||
{ | ||
MergeAttribute(context.Attributes, "data-val", "true"); | ||
MergeAttribute(context.Attributes, "data-val-requiredif", this.ErrorMessage); | ||
string watched = _watchedField; | ||
var containerName = context.ModelMetadata.ContainerType.Name; | ||
if (!String.IsNullOrEmpty(containerName)) | ||
{ | ||
watched = containerName + "." + _watchedField; | ||
} | ||
MergeAttribute(context.Attributes, "data-val-requiredif-watchedfield", watched); | ||
MergeAttribute(context.Attributes, "data-val-requiredif-watchedfieldvalue", _watchedFieldValue); | ||
} | ||
|
||
/// <summary> | ||
/// See https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-7.0#iclientmodelvalidator-for-client-side-validation | ||
/// </summary> | ||
private static bool MergeAttribute(IDictionary<string, string> attributes, string key, string value) | ||
{ | ||
if (attributes.ContainsKey(key)) | ||
{ | ||
return false; | ||
} | ||
|
||
attributes.Add(key, value); | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.