Hidden Field in sitelet Piglets
Closed this issue · 4 comments
Hi Taha!
I have added a text box field
Adding value in the text box from jQuery successfully
But when i am submitting form its not taking into post till that i manually CHANGE that text field.
let blogPiglet (init:LoginInfo) =
Piglet.Return (fun hiddenblogid comment -> LoginInfo.New hiddenblogid comment)
<*> (Piglet.Yield init.Hiddenblogid)
<*> (Piglet.Yield init.Comment
|> Piglet.Validation.Is Piglet.Validation.NotEmpty "Add your comment first")
|> Piglet.WithSubmit
let blogRender hiddenblogid comment submit =
Div [Attr.Class "well"; Attr.Id "common-form"] -< [
Div [Attr.Class "form-group"] -< [
H2 [Text "Add your comments"]
]
Div [Attr.Class "form-group"] -< [
Controls.Input hiddenblogid-< [
Attr.Class "form-control"
Attr.Id "commentId"
]
]
Can you paste the jQuery bits used to set the field?
Yes
I am using it in javascript below works fine no problem
$(window).bind("load", function () {
// $('input#commentId').val(window.location.href);
var blogId = getUrlVars()["blogId"];
$('input#commentId').val(blogId);
});
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
Above Jquery works fine but still its required to manual change value then form submission requires values
I think that you're placing your script above the WebSharper generator meta tag. Move it to the bottom of the page before the closing body tag.