Getting data from a text area using Crafty.js with CoffeeScript

246 views Asked by At

I've got some code working in CoffeeScript with Crafty.js.

I've created a pop-up and want the users to write down register data, but, somehow, it's not working.

Can you point me out where's the error?

Here's the code:

class registerDlg extends Dlg
  constructor: (text, fun) ->
  text = """
  <p>Username:</p>
    <textarea id="name-textarea" placeholder="username"></textarea>
  <p>Password:</p>
    <textarea id="password-textarea" placeholder="password"></textarea>
  <p>Email</p>
    <textarea id="email-textarea" placeholder="email"></textarea>
  """
  $nameText = $('#name-textarea')
  $emailText = $('#email-textarea')
  $passwordText = $('#password-textarea')
  if !fun
    fun = -> closeDlg(this)
  onReady = ->
    inner.append(text)
    inner.append("""
      <div id="sendBtn" class="btn-green">Register</div>
      <div id="#{@id}-confirm" class="btn-blue">Later</div>
    """)
    $("##{@id}-confirm").click( => fun.call(@))
    $(sendBtn).click( =>
      if isEmptyStr($nameText.val()) or isEmptyStr($emailText.val()) or isEmptyStr($passwordText.val())
        fun = -> closeDlg(this)
      else
        loader.show()

        window.folder.registerData($nameText.val(), $emailText.val(), $passwordText.val(), (data)->
          loader.hide()
          if data.result == 'ok'
            closeDlg(this)
          else
            fun = -> closeDlg(this)
          )
      )

If, in registerData, I change, for example, $nameText.val() for "testArray" it sends the array correctly, but, in the original way, it sends nothing.

Any ideas?

0

There are 0 answers