Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 20, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 20, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 20, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 20, 2025

      GPT-5 should have a higher “degree of scientific certainty” than the current ChatGPT — but with less model switching

      May 20, 2025

      Elon Musk’s Grok 3 AI coming to Azure proves Satya Nadella’s allegiance isn’t to OpenAI, but to maximizing Microsoft’s profit gains by heeding consumer demands

      May 20, 2025

      One of the most promising open-world RPGs in years is releasing next week on Xbox and PC

      May 20, 2025

      NVIDIA’s latest driver fixes some big issues with DOOM: The Dark Ages

      May 20, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Community News: Latest PECL Releases (05.20.2025)

      May 20, 2025
      Recent

      Community News: Latest PECL Releases (05.20.2025)

      May 20, 2025

      Getting Started with Personalization in Sitecore XM Cloud: Enable, Extend, and Execute

      May 20, 2025

      Universal Design and Global Accessibility Awareness Day (GAAD)

      May 20, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      GPT-5 should have a higher “degree of scientific certainty” than the current ChatGPT — but with less model switching

      May 20, 2025
      Recent

      GPT-5 should have a higher “degree of scientific certainty” than the current ChatGPT — but with less model switching

      May 20, 2025

      Elon Musk’s Grok 3 AI coming to Azure proves Satya Nadella’s allegiance isn’t to OpenAI, but to maximizing Microsoft’s profit gains by heeding consumer demands

      May 20, 2025

      One of the most promising open-world RPGs in years is releasing next week on Xbox and PC

      May 20, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: Required Requirements

    CodeSOD: Required Requirements

    August 6, 2024

    Sean was supporting a web application which, as many do, had required form fields for the user to fill out. The team wanted to ensure that the required fields were marked by an “*”, as you do. Now, there are a lot of ways to potentially accomplish the goal, especially given that the forms are static and the fields are known well ahead of time.

    The obvious answer is just including the asterisk directly in the HTML: <label for=”myInput”>My Input(*)</label>: <input…>. But what if the field requirements change! You’ll need to update every field label, potentially. So someone hit upon the “brillant” idea of tracking the names of the fields and their validation requirements in the database. That way, they could output that information when they rendered the page.

    Now, again, an obvious solution might be to output it directly into the rendered HTML. But someone decided that they should, instead, use a CSS class to mark it. Not a bad call, honestly! You could style your input.required fields, and even use the ::before or ::after pseudoelements to inject your “*”. And if that’s what they’d done, we wouldn’t be talking about this. But that’s not what they did.

    <head>
    <script type=“text/javascript”>

    $(document).ready(function () {

    //Adds asterisk on required fields
    $(“.requiredField”).prepend(“* “);

    });

    </script>
    </head>
    <body>
    <div id=“first” class=“displayBlock”>
    <div class=“fieldlabel”>
    <span class=“requiredField”></span>First Name:</div>
    @Html.TextBoxFor(i => Model.Applicant.FirstName)
    <div class=“displayBlock”>@Html.ValidationMessageFor(i => Model.Applicant.FirstName)</div>
    </div>
    </body>

    This is a Razor-based .NET View. You can see, in this trimmed down snippet, that they’re not actually using the database fields for remembering which UI elements are required, and instead did just hard-code it into the HTML. And they’re not using CSS to style anything; they’re using JQuery to select all the .required elements and inject the “*” into them.

    This, by the way, is the only reason this application ever uses JQuery. The entire JQuery library dependency was added just to handle required fields. Fields, which we know are required because it’s hard-coded into the page body. Which raises the question: why not just hard-code the asterisk too? Or are we too worried about wanting to stop using “*” someday in lieu of “!”?

    At this point, the code is fairly old, and no one is willing to okay a change which impacts multiple pages and doesn’t involve any newly developed features. So this odd little plug of JQuery for JQuery’s sake just sorta sits there, staring at Sean every day. No one wants it there, but no one is going to be the one to remove it.

    [Advertisement]
    Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow can business leaders ready their organizations for AI? 4 keys to success
    Next Article Modern WYSIWYG Rich Text Editor For React – rc-tiptap-editor

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 20, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-30193 – DNSdist TCP Stack Exhaustion Denial of Service Vulnerability

    May 20, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Apple smart home camera and new AirPods feature rumors swirl – what to know

    Development

    Buy a BJ’s membership for just $20 right now

    Development

    Microsoft says its killing Windows Control Panel – here’s why I’m not holding my breath

    Development

    The First Look of Android 16, Wear OS Bold New Redesign is OUT Featuring Material 3 Expressive [WATCH]

    Operating Systems

    Highlights

    Amazon DocumentDB Quick Start: Zero Setup with AWS CloudShell

    March 16, 2025

    Amazon DocumentDB (with MongoDB compatibility) launched its integration with AWS CloudShell. With this integration, you…

    Add Comments to your Laravel Application with the Commenter Package

    July 27, 2024

    Amazon Bedrock Prompt Management is now available in GA

    November 7, 2024

    Email your conversations from Amazon Q

    January 9, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.