Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed :key (in addition to :message) #30

Closed
wants to merge 2 commits into from
Closed

Exposed :key (in addition to :message) #30

wants to merge 2 commits into from

Conversation

aajhiggs
Copy link

I have found use case where I could do with the key of the error array exposed (proposing :key).

If I echo out my errors, on some occasions I output the errors in a single block then treat them using JS (usually moving them to an element on the page by the ID stored in a data attribute).

If I want to print

  • :message
  • , I cannot currently access the :key part (where :key is the ID of the associated field).

    Being able to do this (as adjusted) allows a user to identify exactly what field an individual message was associated with e.g. when using ->all(), and is a simple exposure of data already held in the object.

    Example:

    Format:

    <li data-key=":key">:message</li>
    
    <ul class="errors">
        <li data-key="item_firstname">You didn't enter your first name</li>
    </ul>
    

    I have a use case where I could do with :key exposed.
    
    If I echo out my errors, on some occasions I output the errors in a single block then treat them using JS (usually moving them to an element on the page by the ID stored in a data attribute).
    
    If I want to print <li data-key=":key">:message</li>, I cannot currently access the :key part (where :key is the ID of the associated field).
    
    Being able to do this (as adjusted) allows a user to identify exactly what field an individual message was associated with e.g. when using ->all(), and is a simple exposure of data already held.
    @franzliedke
    Copy link
    Contributor

    Please take into account Laravel's coding standards:

    • spaces between array elements
    • the variable name should be $messagesKey

    Updates following comments by franzliedke
    @aajhiggs
    Copy link
    Author

    @franzliedke I think corrected it as I understand from what you've said. Apologies for the basic error, still getting to grips with keeping my work super neat!

    @bencorlett
    Copy link
    Contributor

    Are you able to provide a couple of tests for this?

    I think this is pretty sweet :)

    @daylerees
    Copy link
    Contributor

    +1 to @bencorlett it would be nice to have some tests. Let's try and keep the code coverage for L4 as high as possible shall we chaps?

    @taylorotwell
    Copy link
    Member

    Done. I added tests.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    5 participants