원클릭으로
frontend-patterns
Frontend JavaScript patterns for event handling, form UX, and validation integration
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Frontend JavaScript patterns for event handling, form UX, and validation integration
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Authorization Code Flow for web applications using MSAL.NET confidential client to sign in users and access APIs on their behalf
Handle MSAL distributed token cache collisions and stale entries in ASP.NET Core applications
On-Behalf-Of (OBO) Flow for web APIs to call downstream APIs while preserving user identity in MSAL.NET
{what this skill teaches agents}
Review API DTO implementations for contract/domain separation, mapping patterns, and REST compliance
This skill should be used when the user asks to "build a feature", "fix a bug", "implement something", "start a dev cycle", types "/dev", or describes a software task that requires design, implementation, testing, and shipping. Orchestrates the full software development lifecycle from interrogation through shipping, with self-learning that improves over time.
| name | frontend-patterns |
| description | Frontend JavaScript patterns for event handling, form UX, and validation integration |
Applicable to: Web layer JavaScript (site.js, page-specific scripts)
Last Updated: 2026-04-11
Maintainer: Sparks (Frontend Developer)
When writing event listeners that conditionally block browser default behavior, always accept the event parameter and call preventDefault() before early returns.
❌ WRONG:
form.addEventListener('submit', function () {
if (someCondition) return; // ⚠️ Form still submits!
// ... handler logic
});
✅ CORRECT:
form.addEventListener('submit', function (event) {
if (someCondition) {
event.preventDefault(); // ✅ Form submission blocked
return;
}
// ... handler logic
});
preventDefault() don't stop the browser's default actionThe project's global form submit handler (site.js) implements double-submit prevention. IMPORTANT: Use button click event, NOT form submit event, to prevent race conditions.
❌ WRONG - Race Condition:
form.addEventListener('submit', function (event) {
if (btn.disabled) {
event.preventDefault();
return;
}
btn.disabled = true; // ⚠️ Too late! Second click already queued submit event
});
✅ CORRECT - Click Event:
btn.addEventListener('click', function (event) {
if (btn.disabled) {
event.preventDefault(); // Block if already disabled
return;
}
// Check client validation BEFORE disabling
if (typeof $ !== 'undefined' && $(form).valid && !$(form).valid()) {
return; // Let validation run, don't disable
}
btn.disabled = true; // Disable immediately on first click
btn.innerHTML = '<span>...</span>Saving...'; // Visual feedback
});
Why Click Event Prevents Race:
Key Points:
invalid-form.validate eventUse Bootstrap spinner for loading states:
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"></span>Saving...';
Store original button HTML to restore on error:
btn.dataset.originalHtml = btn.innerHTML; // Save before change
// ... later, on error:
btn.innerHTML = btn.dataset.originalHtml; // Restore
delete btn.dataset.originalHtml;
The project uses jQuery Unobtrusive Validation. Listen for validation failures to reset button state:
$(form).on('invalid-form.validate', function () {
// Restore button if it was disabled for submit
if (btn.dataset.originalHtml) {
btn.innerHTML = btn.dataset.originalHtml;
delete btn.dataset.originalHtml;
btn.disabled = false;
}
});
JosephGuadagno.Broadcasting.Web/wwwroot/js/site.js.squad/decisions/inbox/switch-real-fix-708.md (2026-04-13)When a controller POST action has simple-type parameters (int, string, guid) that are NOT properties of the ViewModel, those parameters MUST be included in the route. Without them, ASP.NET Core routing cannot match the action, causing HTTP 400 Bad Request.
❌ WRONG:
@model EngagementSocialMediaPlatformViewModel
<!-- Missing route parameter - causes 400 error! -->
<form asp-action="AddPlatform" method="post">
<input type="hidden" asp-for="EngagementId" />
<!-- ... -->
</form>
Controller:
[HttpPost]
public async Task<IActionResult> AddPlatform(int engagementId, EngagementSocialMediaPlatformViewModel vm)
{
// ⚠️ Form POSTs to /Engagements/AddPlatform (no engagementId in route)
// ⚠️ ASP.NET Core expects route like /Engagements/AddPlatform/5
// ⚠️ Route doesn't match → HTTP 400
}
✅ CORRECT:
@model EngagementSocialMediaPlatformViewModel
<!-- Route parameter required for action matching -->
<form asp-action="AddPlatform" asp-route-engagementId="@Model.EngagementId" method="post">
<input type="hidden" asp-for="EngagementId" />
<!-- ... -->
</form>
Controller:
[HttpPost]
public async Task<IActionResult> AddPlatform(int engagementId, EngagementSocialMediaPlatformViewModel vm)
{
// ✅ Form POSTs to /Engagements/AddPlatform/5
// ✅ Route matches action signature
// ✅ engagementId = 5 (from route), vm.EngagementId = 5 (from POST body)
}
Having BOTH asp-route-X and a matching ViewModel property is NOT a conflict:
Use route parameters (asp-route-*) when:
Action(int id, ViewModelType model)Use model properties (hidden fields) when:
vm.EngagementId used to verify data integrityUse BOTH when:
Action(int routeParam, ViewModelType vm) where vm has a property matching routeParam.squad/decisions/inbox/sparks-708-route-parameter-correction.md (SUPERSEDES previous incorrect decision)JosephGuadagno.Broadcasting.Web/Views/Engagements/AddPlatform.cshtml