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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 19, 2025

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

      May 19, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 19, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 19, 2025

      Computex

      May 19, 2025

      DOOM: The Dark Ages gets Path Tracing update in June, bringing better visuals for PC players

      May 19, 2025

      Early Memorial Day deals are LIVE on Windows PCs, gaming accessories, and more — 6 hand-picked discounts on our favorites

      May 19, 2025

      Microsoft open sources the Windows Subsystem for Linux — invites developers to help more seamlessly integrate Linux with Windows

      May 19, 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

      How JavaScript’s at() method makes array indexing easier

      May 19, 2025
      Recent

      How JavaScript’s at() method makes array indexing easier

      May 19, 2025

      Motherhood and Career Balance in Tech: Stories from Perficient LATAM

      May 19, 2025

      ES6: Set Vs Array- What and When?

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

      Computex

      May 19, 2025
      Recent

      Computex

      May 19, 2025

      DOOM: The Dark Ages gets Path Tracing update in June, bringing better visuals for PC players

      May 19, 2025

      Early Memorial Day deals are LIVE on Windows PCs, gaming accessories, and more — 6 hand-picked discounts on our favorites

      May 19, 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-4951 – Rapid7 AppSpider Pro Stored Cross-Site Scripting Vulnerability

    May 20, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Cyberattack Disrupts Japan Airlines Operations, Delays Over 40 Flights

    Development

    Gladys Assistant – privacy-first home assistant

    Development

    This Dell laptop with a Snapdragon X Plus is under $600 right now

    News & Updates

    Redefining creativity with Substance 3D tools, stunning designs, and artistic triumphs

    Development

    Highlights

    Development

    UAE Leads the Charge: Top Cybersecurity Trends Shaping the META Region

    June 2, 2024

    The United Arab Emirates (UAE) has carved a niche for itself as a beacon of…

    Google DeepMind Introduces a Parameter-Efficient Expert Retrieval Mechanism that Leverages the Product Key Technique for Sparse Retrieval from a Million Tiny Experts

    July 11, 2024

    Do Reasoning Models Really Need Transformers?: Researchers from TogetherAI, Cornell, Geneva, and Princeton Introduce M1—A Hybrid Mamba-Based AI that Matches SOTA Performance at 3x Inference Speed

    April 18, 2025

    AI-Designed bobblehead

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

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