Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:36:51+00:00 2026-06-17T10:36:51+00:00

Im trying to make an order form with Play 2 and Scala. Here is

  • 0

Im trying to make an order form with Play 2 and Scala.

Here is what it was before grouping:

<table>
  @items.zipWithIndex.map {
    case (item, index) =>
      @itemRow(item, index)
  }
</table>

itemRow definition

@itemRow(index: Int, item: Item) = {
    <tr>
        <td>
        @(index+1)
        </td>
        <td>
        @item.name
        </td>
        <td>
            <input type="hidden" name="@requestForm("items")("[" + index + "]")("itemId").name" value="@item.id">
            <input type="text" name="items[@index].count" value="@requestForm("items")("[" + index + "]")("count").value">

        </td>
    </tr>
}

At first I tried naive implementation

@items.groupBy(item => item.category).map {
  case (categoryId, itemsInCategory) =>
    <table>
      @itemsInCategory.zipWithIndex.map {
        case (item, index) =>
          @itemRow(item, index)
      }
    </table>
}

But there is a problem, indexes in each category starts with 0.

So, http request is something like that:

# category 1
items[0].id = 1
items[0].count = 1
items[1].id = 2
items[1].count = 2

# category 2
items[0].id = 3
items[0].count = 1
items[1].id = 4
items[1].count = 5

And it is causes to values being overriden.
I need my indexes for be consecutive within the form, like this:

# category 1
items[0].id = 1
items[0].count = 1
items[1].id = 2
items[1].count = 2

# category 2
items[2].id = 3
items[2].count = 1
items[3].id = 4
items[3].count = 5

So there is questions

For functional programmers:

  • Can I make index variable shared for all groups?

For Play 2.0 or web programmers:

  • Is there another way to make form with variable count of repeated values?
  • How to avoid sending this bunch of items with 0 count?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:36:52+00:00Added an answer on June 17, 2026 at 10:36 am

    I have no experience with Play so I can’t comment on the Play specific questions (maybe it already provides helpers for what you want), but on the scala librayr alone you can do something like this:

    @items.sortBy(item => item.category).zipWithIndex.groupBy{ case (item, _) => item.category}.map {
      case (categoryId, indexedItemsInCategory) =>
        <table>
          @indexedItemsInCategory.map {
            case (item, index) =>
              @itemRow(item, index)
          }
        </table>
    }
    

    The idea is to first sort the items by category and then zip them with the corresponding indexes. Then only you group them by category (which should be fast as the list is already sorted).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a small pizza order form, but I have a
I am trying to make a simple form activity in order to learn how
I am trying to make an ORDER BY FIELD work with a wildcard, and
In order to condense my code I am trying to make one of my
In order to cleanly port my game to the iPhone, I'm trying to make
I'm trying to solve the relational model in order to make a Django app.
I've been trying to pair NIO with multithreaded read handling in order to make
I'm currently trying to create a subclass of UIImageView in order to make it
I'm trying to make a calculator using Objects. Here is JSFiddle: http://jsfiddle.net/jNqEv/4/ I was
I'm working with a GUI in PowerShell and trying to make the form such

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.