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 8506209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:31:54+00:00 2026-06-11T02:31:54+00:00

So for a system I am developing I am trying to do something similar

  • 0

So for a system I am developing I am trying to do something similar to this:

If I have a Model called User, that has an _id (ObjectId), username, password, and then I am trying to create a new appointment, my form would look for a patient (display the patient name in the dropdown but really would pick up the patient’s ObjectId), and appointment time.

Now I’ve looked everywhere and can’t find anything remotely close to the solution i’m trying to attain.

In Application.scala, I have:

val appointmentForm= Form(
  tuple(
    "patient" -> nonEmptyText, // ObjectId
    "startTime" -> nonEmptyText))

I am not sure how to quite work my view in order to reflect the patient. I know you have to do something like this:

@select(appointmentForm("patient"), options(..)

Can anyone give me any ideas as to how I can look up the patients for this example to pick up a Mongo ObjectId.

The ORM I am using btw is https://github.com/leon/play-salat

  • 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-11T02:31:55+00:00Added an answer on June 11, 2026 at 2:31 am

    here is an example how I would do it:

    routes:

    GET      /test        controllers.Test.show
    POST     /test        controllers.Test.submit
    

    view:

    @(f: Form[(ObjectId, String)], users: Seq[(ObjectId, String)])
    @import helper._
    
    @form(action = routes.Test.submit) {
      @select(f("patient"), options = users.map(user => (user._1.toString, user._2)))
      @inputText(f("startTime"))
      <input type="submit" value="Submit!">
    }
    

    controller:

    package controllers
    
    import org.bson.types.ObjectId
    import play.api.data.format.Formatter
    import play.api.mvc._
    import play.api.data.Forms._
    import play.api.data._
    import play.api.data.FormError
    import play.api.Logger
    
    object Test extends Controller {
    
      /**
       * Converts an ObjectId to a String and vice versa
       */
      implicit object ObjectIdFormatter extends Formatter[ObjectId] {
        def bind(key: String, data: Map[String, String]) = {
          val error = FormError(key, "error.required.ObjectId", Nil)
          val s = Seq(error)
          val k = data.get(key)
          k.toRight(s).right.flatMap {
            case str: String if (str.length() > 0) => Right(new ObjectId(str))
            case _ => Left(s)
          }
        }
        def unbind(key: String, value: ObjectId) = Map(key -> value.toStringMongod())
    
        val objectId: Mapping[ObjectId] = of[ObjectId]
      }
    
      // import to get objectId into scope
      import ObjectIdFormatter._
    
      // define user tuples consisting of username and ObjectId for the dropdown. In real lif the list is probably fetched from the db
      def users: Seq[(ObjectId, String)] =
        Seq((new ObjectId("4f456bf744aed129d04db1bd"), "dieter"), (new ObjectId("4faa410b44aec5a0a980599f"), "eva"))
    
      val appointmentForm= Form(
        tuple(
          "patient" -> objectId, // use the ObjectIdFormatter
          "startTime" -> nonEmptyText))
    
    
      def show = Action {
        Ok(views.html.test(appointmentForm, users))
      }
    
      def submit = Action { implicit request =>
        appointmentForm.bindFromRequest.fold(
          formWithErrors => {
            Logger.warn("errors: " + formWithErrors.errors)
            BadRequest(views.html.test(formWithErrors, users))
          },
          formContent => {
            Logger.info("formContent: " + formContent)
            Ok(views.html.test(appointmentForm, users))
          })
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a system, and I have build a code generator that emits a
I am developing a simple system that has unlimited categories and items in each
I'm trying to implement something similar to this or this . I've created a
I am developing a user feedback system using ASP.NET and C#. I have multiple
I'm trying to devise a plugin system for a simple web app I'm developing.
I'm developing a custom trouble ticket system for network management and trying to find
I am developing a SYSTEM app for android to manage user accounts on the
I'm developing a system in Ruby that is going to make use of RabbitMQ
I am developing a system that will receive a XML (XmlDocument) via webservice. I
I'm trying to debug a package that I'm developing. I use a makefile for

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.