How do I hide a field given a checked box? - ruby

I am trying to create a dynamic query page. I am more than happy to learn ruby on rails which is what I am currently doing. However there is a time constraint for this and I have been searching high and low on how to hide a field on a form if a checkbox is checked. I have next to nothing ruby skills and I cant change to another language. Any assistance would be greatly GREATLY appreciated. Also if you know a good tutorial for doing query pages would help!!!

For a form like:
<form ...>
<input id="hide-box" type="checkbox" />
<input id="field-to-hide" />
</form>
You'll need to use something like JQuery to listen for checking and hide accordingly.
$('#hide-box').on('change', function() {
$('#field-to-hide').toggle($(this).prop('checked'));
});

Related

AngularJS : ng-model in ng-repeat

I m beginer in AngularJS, and i try to do this :
<form ng-repeat="prop in tab">
<input ng-model="prop" type="text">
</form>
{{tab}}
With this code inputs values is ok, but when i edit value the reverse binding to "tab" don't work.
How i can simply do this ?
Thanks for yours tips ;)
If you want to see changes in your html document live you either need to move the expression inside the form tag and change it to {{tab.prop}} or outside the tag but also showing the property you are interested in displaying such as {{tab.somePropertyName}}.

No automatic line-break in textarea in Joomla Backend

I'm writing a Module for Joomla! 2.5. In my Backend I've got a textarea, in which values should be written line by line. If the value is to big the line breaks and it looks really confusing and chaotic.
In normal html I would add a wrap="off" to the textarea-tag (I know it's not conform html, but it works), but the textarea is defined in the module's xml-file:
<field name="content" type="textarea" label="LWTAGCLOUD_CONTENT_LABEL" description="LWTAGCLOUD_CONTENT_DESCRIPTION" rows="20" cols="60" class="lw_tagcloud_textarea" default="VALUE; LINK"></field>
Has anyone an idea how to solve this problem?
If you cannot solve the problem using css only, and since you cannot add wrap="off" to the textarea type in Joomla, what you could do is to create a custom parameter type, the same like textarea, just with wrap=off already defined.
For more details on how to do it, have a look at http://docs.joomla.org/Creating_custom_template_parameter_types and http://www.sanjeevshrestha.com.np/2010/01/creating-color-element-in-joomla-for-custom-parameter-type/, it's not hard to make it
just use
for line break !
hope this help for anyone who ask

Passing a document entity to JavaScript functions

This is an elementary problem (I think), and I am embarrassed to ask it here. It may have been answered already, but I could not find it my searches.
In its simplest form, there are two check-boxes, and each CheckBox has a control (e.g, TextBox or DropDownList) associated with it. When the checked state of a CheckBox changes, the associated control must be enabled or disabled.
JavaScript function:
<script type="text/javascript:>
function enable(bValue, control)
{
document.getElementByID(control).Enabled = bValue;
}
</script>
I'd call this function as an event procedure, e.g, enable(this.Checked, "expJob") and enable(this.Checked, "itemJob"), in the HTML below:
<body>
Billable? <asp:CheckBox ID="expBillable" runat="server" Checked="false" OnCheckedChanged="enable(this.Checked, "expJob");" />
to <asp:DropDownList ID="expJob" runat="server" Enabled="true" />
<br /><br />
Billable? <asp:CheckBox ID="itemBillable" runat="server" Checked="false" OnCheckedChanged="enable(this.Checked, "itemJob");" />
to <asp:DropDownList ID="itemJob" runat="server" Enabled="true" />
The problem is that, because of the use of quotes, I am unable to specify the "expJob" parameter in the HTML. Even the use of single quotes does not work.
So the question: Will this approach work? What is the proper syntax?
What is the best way to write and use a function such as this? I am sure such function use will be required when having to iterate over the rows in a grid.
Interestingly, all the questions/answers I have seen use a control's disabled attribute. I am only able to use the Enabled attribute. Can someone explain why, and what the difference is?
You have to use the single quotes ('itemJob')
I think OnCheckChanged is a server event. Asp.net needs a handler in the code behind when you want to use this. Thats why you are getting an error. Find the correct client side event when you want to fire a client side event. Take care of firing postbacks, but default for checkbox is "no auto postback" anyway.
Please be aware that javascript is case sensitive so
document.getElementById is good,
document.getElementByID is bad (note the ID in caps is bad)

I'm looking for a sample javascript to show different hidden inputs if dropdownlist selected value = a specific value. Anyone have anything?

What code would I start with? I know onChange won't work with input=hidden. Would it be best to write something to re-name the hidden fields and then build it into the existing onchange for the dropdown?
Not 100% sure what you are wanting to do. I don't believe its possible to make a tag with <input type="hidden" show on the browser unless you change its type.
Just tested this at W3Schools and worked on Chrome
<input type="hidden" value="OK">
<p id="demo">Click the button below to set the type attribute of the button above.</p>
<button onclick="myFunction()">Try it</button>
<script type="text/javascript">
function myFunction()
{
document.getElementsByTagName("INPUT")[0].setAttribute("type","button");
};
</script>
<p>Internet Explorer 8 and earlier does not support the setAttribute method.</p>
Granted this code obviously states it won't work with IE8 or earlier and it would probably be better to set the id attribute for each of the hidden fields you want and probably use something like document.getElementById(IDVALUE).setAttribute("type", "text") Though this will allow the user to change the value in the tag.
Now all that is left is to give a dropdown with an onChange function that runs a statement like above based on what was selected.

can widgets be cached?

Is there a way to cache widgets. For example if you place your widgets on high volume websites then each time when someone access that site, a call will be made to your server to get the widget code. This way my server can get too much overloaded just to display the widget . Can I cache the widget HTML code and place it on some server like Akamai. Any suggestions or tips highly appreciated.
Thanks in advance.
You sure could, but you'd need to be able to get at the widgets somehow. I've found much higher performance (faster response, faster downloads) from EdgeCast vs. Akamai, also.
Say, for instance, you've got the code for a form at http://cdn.mysite.com/form1.html and a user clicks on a link that would bring up that form.
Use something like this as a script:
$(document).ready( function() {
$(".widget .trigger").click( function() {
url = $(this).attr("rel");
$(this).parents(".widget").load(url, function () {
// Do what needs to be done to the widget code here
// Example: make it an AJAX form.
});
});
});
And then have this Markup:
<div class="widget">
Widget Trigger
</div>
And have this on your CDN:
<form action="/ajax/hander/" method="POST">
<fieldset>
<legend>This is a pretty cool form</legend>
<label for="form1input1">Make this cool:</label>
<input id="form3input1" name="something" type="text" />
<input type="submit" value="Coolify" />
</fieldset>
</form>
You could then have some code server side that uploads snippets to your CDN, saves their URL in a database, and generates the links with the appropriate rel tag by pulling that value from something fast like Memcached. That part will vary greatly based on your language of choice.

Resources