Adding function to a HTML - asp.net-mvc

I need to replace the following helper with its corresponding HTML in a view:
#Html.HelperTextBoxFor(model => model.Length, new { #ng_change = "changeArea()" })
I came up with this:
<input type="text" data-ng-model="MyViewModel.Length" class="form-control" />
But I cannot find where to add the new { #ng_change = "changeArea()"}
Can anyone help me please?

If this #ng_change="..." is an Angular directive, this would look like this in an input tag:
<input type="text" data-ng-model="MyViewModel.Length" class="form-control" ng-change="changeArea()"/>
reference: https://docs.angularjs.org/api/ng/directive/ngChange

You need to get back to the basics here, not sure why you can't figure it out.
http://www.w3schools.com/jsref/event_onchange.asp
<input type="text" data-ng-model="MyViewModel.Length" class="form-control" onchange="changeArea();" />

Related

Permit any parameter nested inside a given param

I have a list of parameters like this:
<input class="form-control" name="analysis[strengths][0]" id="swot_analysis_strengths_0" type="text">
<input class="form-control" name="analysis[strengths][1]" id="swot_analysis_strengths_1" type="text">
...
etc
Then there's also
<input class="form-control" name="analysis[weaknesses][x]" id="swot_analysis_strengths_2" type="text">
<input class="form-control" name="analysis[opportunities][x]" id="swot_analysis_strengths_2" type="text">
<input class="form-control" name="analysis[threats][x]" id="swot_analysis_strengths_2" type="text">
In my controller I have
params.require(:swot_analysis).permit(:strengths, :weaknesses, :opportunities, :threats)
That doesn't work. The only way I've got it to work so fat is by doing this
sanitized_params = params.require(:swot_analysis).permit(:strengths =>['0','1'], :weaknesses =>['0','1'], :opportunities =>['0','1'], :threats =>['0','1'])
However the number of members for each array will vary, users will be able to add and remove members as they please. So I need a method to simply permit any sub-param of the original for parameters.
Would be nice to allow it only if it's a number, but not really a priority right now
This should take care of the member array lengths:
params.require(:swot_analysis).permit(:strengths =>[], :weaknesses =>[], :opportunities =>[], :threats =>[])
http://api.rubyonrails.org/classes/ActionController/Parameters.html

Passing Connectionstring as parameter in SSRS through URL

I am working on an application using Classic ASP and SQL Server 2008 R2. We are using SSRS for the reports. Now the datasource changes depending on the user. I have been using a parameter for the connectionstring. It is working fine but the problem is the connectionstring shows in the URL. Is there a way to hide it? Or is there a better way.
Please Help.
Yes - change the method on your form to POST and use the Request.Form syntax instead of Request.QueryString:
<form id="myForm" method="post" action="myPage.asp">
<label for="txtBox">Type something</label>
<input type="text" id="txtBox" name="txtBox" />
</form>
<%
Dim value
value = Cstr(Request.Form("txtBox"))
If value <> "" then
'Do your processing
End if
%>
-- EDIT --
To be honest, though, I would not store my connection string on my form like this. You'd be far better off storing it in an Application level variable, like so:
Application("CON_STRING") = "...blahblahblah..."
This should be stored in the Application_OnStart event of the Global.asa* file.
*
Apologies for the link to w3schools - it was the best at the time!
-- EDIT 2 --
Try using an iframe to display the info...
<form id="frmRender" action="ABCD/ReportServer?/Reports/rptSalesReport.rpt"; method="post" target="_blank">
<input type="hidden" name="rs:Command" value="Render">
<input type="hidden" name="rc:LinkTarget" value="_blank">
<input type="hidden" name="rs:Format" value="HTML4.0">
<input type="hidden" name="rc:Parameters" value="False">
<input type="hidden" name="ConnectionString" value="<%=Session("ConnectionString")%>">
<input type="hidden" name="StartDate" value="<%=StartDate%>">
<input type="hidden" name="EndDate" value="<%=EndDate%>">
<a id="linkInfo" href="javascript:generateSsrs();">Generate Report</a>
<iframe id="ssrsReport" class="reportHeightWidth"></iframe>
</form >
<script language="javascript">
function genreateSsrs() {
document.getElementById("ssrsReport").src = "ABCD/ReportServer?/Reports/rptSalesReport.rpt?rs:Command=Render&rc:LinkTarget=top&rs:Format=HTML4.0&rc:Parameters=False&ConnectionString=<%=Server.URLEncode(Session("ConnectionString"))%>&StartDate=<%=StartDate%>&EndDate=<%=EndDate%>";
}
</script>
That's a rough version, but it's untested, so may need some tweaks.
In you code, use the below code
="Data Source="+Parameters!DatabaseServerName.Value+";Initial Catalog="&Parameters!DatabaseCatalogName.Value

How to upload files in grails webflow?

I try to build a grails webflow containing a step which has a file upload field in it. Can't find a clear example. How can I do it?
The form looks like this:
<g:form method="POST" action="upload" enctype="multipart/form-data">
<input type="file" name="myFile" />
<input type="submit" value="Upload! " />
</g:form>
The flow looks like this:
def rgdpsRequestFlow = {
chargeCheck{
on("upload"){
println "Hello file upload"
}.to("uploadSuccess")
}
uploadSuccess{
}
}
When I submit the form I get
HTTP Status 404 - /webflowTest/mortgage/upload
It's a little unclear which part you're struggling with. If you need help with the file upload, you may want to try the Grails File Uploader plugin, or otherwise check out this step-by-step tutorial or use the uploadForm tag that James Kleeh has pointed out.
Namely, in the gsp you can add:
<g:uploadForm controller='yourControllerName' action='save'>
<input type='file' name='file'/>
<input type='submit'/>
</g:uploadForm>
Then handle it in the controller:
def save = {
def file = request.getFile('file').inputStream.text
file.transferTo(new File('someLocation/filename'))
}
The problem was I used g:form action attribute.
The correct way to use file upload with webflow is using g:submitButton
Here is the form code that works fine with my webflow:
<g:form method="POST" enctype="multipart/form-data">
<input type="file" name="myFile" />
<g:submitButton class="save" name="upload" value="Upload!"/>
</g:form>

Saving Set of Domains For a Parent

I have the following Domains:
class Attribute {
static hasMany = [attributeParameters: AttributeParameter]
}
class AttributeParameter {
String value
Integer sequenceNo
static belongsTo = [attribute: Attribute]
}
I have a form where I want to display all the existing AttributeParameters for an Attribute and allow the user to populate their values and click Save. On Save, each AttributeParameter (which already has an ID) needs to be updated.
I'm currently drawing a blank on how I need to create the HTML for this to work. I've tried this:
Code simplified to clarity:
<form>
<input type="hidden" name="attributeParameters[0].id" value="1" />
<input type="text" name="attributeParameters[0].value" value="1234567" />
<input type="hidden" name="attributeParameters[1].id" value="2" />
<input type="text" name="attributeParameters[1].value" value="name" />
</form>
def save() {
def attribute = Attribute.get(params.id)
attribute.properties = params
}
and it populates the collection correctly, but it doesn't work because the AttributeParameter isn't being fetched before the save, so it is failing with an error:
A collection with cascade="all-delete-orphan" was no longer referenced
by the owning entity instance: com.foo.Attribute.attributeParameters
UPDATE:
I modified the HTML to the following:
<form>
<input type="hidden" name="attributeParameters.id" value="1" />
<input type="text" name="attributeParameters.value" value="1234567" />
<input type="hidden" name="attributeParameters.id" value="2" />
<input type="text" name="attributeParameters.value" value="name" />
</form>
And the controller:
params.list('attributeParameters').each {
def ap = AttributeParameter.get(it.id)
ap.value = it.value
ap.save()
}
This works. My only concern is the order in which the parameters come in. If they always come into the params object in the same order they show up on the form, then I should be ok. but if they ever come in differently, I could be modifying the value of the wrong AttributeParameter.
So still looking for a better way or some sort of verification that they params will always be first in-first out.
UPDATE 2:
I ran across this post and it is what I want but I cannot change Attribute.attributeParameters into a List. They need to stay as a Set.
Could you do something like this:
<form>
<input type="text" name="attributeParameter.1" value="1234567" />
<input type="text" name="attributeParameter.2" value="name" />
</form>
Where you create the names and values dynamically from each AttributeParameter:
<g:textField name="attributeParameter.${attributeParameterInstance.id}" value="${attributeParameterInstance.value}" />
And then in your controller
params.attributeParameter.each {id, val->
def ap = AttributeParameter.get(id)
ap.value = val
ap.save()
}
That way you have the actual id of each parameter directly and it wouldn't matter which order they were processed.

AngularJS how to bind maps

Here is my HTML:
<div ng-app="angularApp">
<div ng-controller="testCtrl">
testKey = {{testKey}}<br />
Test 1: <input type="text" ng-model="test.myKey" />{{test[testKey]}}<br />
Test 2: <input type="text" ng-model="test[testKey]" />{{test[testKey]}}
</div>
</div>
Here is the js:
angular.module('angularApp', []);
function testCtrl($scope)
{
$scope.testKey = "myKey";
}​
I setup and example here
Why does Test 1 work but Test 2 not work? Are "[" not allowed in the ng-model directive?
Here a working example. The problem is very simple, test.[testKey] isn't valid, you want test[testKey]. And you need to define test as an object on the controller because you cannot set a property of an undefined variable.

Resources