@jussi nice example
I guess it would not be advisable to use it to input long texts, since you can’t move around the text as well as copy/paste… but if you need to insert just few lines, it could work nicely [import]uid: 9158 topic_id: 7076 reply_id: 49777[/import]
I am trying to use the webpopup for now although it’s very ugly with the gray. Does anyone know how to pass the text from a TEXTARE from the webpopup to corona? Something doing with the urlrequest function.
Thanks [import]uid: 8192 topic_id: 7076 reply_id: 52871[/import]
@jussi,
Do you know if you can pass the text that is typed in the TEXTAREA in the HTML form to Lua with the urlRequest? [import]uid: 8192 topic_id: 7076 reply_id: 52872[/import]
place it in a form and set method as “get”, and set action something like, “corona:form”. when you submit, it should create a url like “corona:form?textareaname=content”, then use string functions to retrieve “content”. [import]uid: 46529 topic_id: 7076 reply_id: 52889[/import]
@culutas Thank you so much. I am now one step closer.
I now get the output as such:
corona:form?text=Content+Text+%0D%0A
my inputted text was "Content Text "
If anyone has any suggestions on how to clean this up to get it back to string. I think we will have a workaround that works. [import]uid: 8192 topic_id: 7076 reply_id: 52897[/import]
Basically you need an url decoder (http://meyerweb.com/eric/tools/dencoder/), in PHP it should be urldecode.
Try to look here http://lua-users.org/wiki/StringRecipes
the example “Decode an URL-encoded string” might work -can’t do any test right now- [import]uid: 9158 topic_id: 7076 reply_id: 52976[/import]
Ok guys. I have something working but need some help.
Here is the code for a newTextField:
function newTextField (x,y, width, height, name, startText,fontSize,borderThickness)
local rows = math.ceil(height/fontSize)
local realHeight = height + 50 -- To include submit button
local textAreaWidth = width-20
local htmlContent = [[
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<form action="corona:form" method:="get" enctype:="multipart/form-data">
<br> <textarea name="]]..name..[[" rows="]]..rows..[[" style="width:]]..textAreaWidth..[[px">]]..startText..[[ here</textarea><br> <br> <input type="submit" value="Done" style="position:relative; top:3px; left: 1%;"><br> </form>
[/html]]]
--print(htmlContent)
--Create HTML File. Make sure that each textfield has a different name
local path = system.pathForFile( name..".html", system.DocumentsDirectory )
fh = io.open( path, "w" )
fh:write( htmlContent )
io.close( fh )
--Location of HTML File
local url = name..".html"
local function urlHandler(event)
local str = event.url
if string.find( str, "file:" ) == nil then
--Decode URL Format into normal string text
function url\_decode(str)
str = string.gsub (str, "corona:form", "")
str = string.gsub (str, "?text=", "")
--Can't seem to get rid of this properly. It's when the text goes to the next line.
str = string.gsub (str, '[%0D%0A]'," ")
--
str = string.gsub (str, "+", " ")
str = string.gsub (str, "%%(%x%x)",
function(h) return string.char(tonumber(h,16)) end)
str = string.gsub (str, "\r\n", "\n")
return str
end
str=url\_decode(str)
--Text for Debugging. Make your string go where you want here.
local myText = display.newText(str, 20, 240, native.systemFont, 16)
myText:setTextColor(255, 255, 255)
end
return str
--return true
end
-- Options for the web view.
local options = { hasBackground=false, baseUrl=system.DocumentsDirectory, urlRequest=urlHandler }
-- Open my website in a web view.
native.showWebPopup(x,y,width,realHeight, url, options )
end
newTextField(0,0,320,100,"text","This is the starting Text",15,0)
I have little or no knowledge of HTML and CSS so. Please help me out with some of the formatting.
This code creates a new HTML file for a new text field.
Current Issues that I need help with:
-There seems to be some padding around the textfield that I can’t get rid of.
-The creation of the new file part should be altered so that if the file already exists, it overwrites it.
-Each text field must have a different name.
-Can’t find a way around having a submit button after the textarea. I would like to use the DONE button that appears with the keyboard.
-I can’t get rid of the next line coding “%0D%0A” fully. I am trying to convert next line to just a space.
Please feel free to alter this code and post here the changes. We are nearly there. [import]uid: 8192 topic_id: 7076 reply_id: 53013[/import]
You can try my code and app.
One of its functions is to help you activate a textfield on your device when you touch the fake one in the simulator.
code: http://developer.anscamobile.com/code/coremoter#comment-48593
app: http://developer.anscamobile.com/showcase/coremoter
[import]uid: 35642 topic_id: 7076 reply_id: 53286[/import]
OMG OMG OMG! Thanks Ansca!!!
Finally in the latest daily builds we have the isEditable option in textboxes!!!
Native multi-line text input! Yahoooo Yahooo!! [import]uid: 9158 topic_id: 7076 reply_id: 54138[/import]