dimanche 1 février 2015

add Taggings record to Post and Tag with Rails 4 nested form

I have 3 models, Post, Tag and Taggings and I am trying to build a form to create the taggings through an array of checkboxes. I can't seem to get ANY of the Tagging records to save (even though it



<%= form_for @post %>
<%= hidden_field_tag "post[tag_ids][]", nil %>
<% Tag.colors.each do |tag| %>
<%= check_box_tag "post[tag_ids][]", tag.id, @post.tag.include?(tag), id: dom_id(tag)
%>
<%= label_tag dom_id(tag), tag.name %><br>
<% end %>
<label>Post title</label>
<%= text_field :title %>

<%= submit_tag 'ADD TAGS' %>


Controller



class PostsController < ApplicationController

def add_taggings
@post = Post.find(params[:id])
@taggings = Tagging.new
if @post.update_attributes(post_params)
redirect_to @Post
flash[:notice] = "Successfully Tagged

else
render :edit
end
end

def post_params
params.require(:post).permit( :id, :title, :img, :content, :author,
taggings_attributes:[:id, :post_id, :tag_id, {:tags => []}, {:posts => []}, :_destroy])


Models



class Post < ActiveRecord::Base
has_many :taggings

class Tag < ActiveRecord::Base
has_many :taggings

class Tagging < ActiveRecord::Base
belongs_to :tag
belongs_to :post
validates_uniqueness_of :tag, :scope => :post_id




using Databinder.Eval in onclick of checkbox in datagrid


<asp:DataGrid ID="dg" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="cb" runat="server" onclick='myCheckChanged("<%#DataBinder.Eval(Container, "DataItem.myid")%>")' />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>


This runs but when I click the checkbox in the browser I get a js error. I tried all the combinations of single and double quotes and escaping but i either get a js error or a .net "The server tag is not well formed" error. how can I do this?





How to unselect and undo with checkboxes using Java Swing?

I have a checkbox, when the checkbox is selected I want to add int 2 to my total. Then I want to be able to unselect it and then subtract int 2 to my total.


At the moment, I cant unselect and subtract 2.


Also, my checkbox is in a button group so I need to use clearSelection() as a solution to deselect.


The code I currently have for this is (which isn't work too well):



monTill4ChckBox.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

if(monTill4ChckBox.isSelected()){

mondayCost= mondayCost + 2;
}
else{
mondayCost= mondayCost - 2;
monAftergroup.clearSelection();
}




Change the color of text with a dynamic checkbox

I'm working on a to do list. I can enter text within a field and create a new item with a checkbox, but I cannot get the checkbox to do anything. I would like to change the color of the text once the checkbox has been clicked





function todoadd() {
todoNew = new objectTodo();
}

function objectTodo() {
var todo = document.getElementById('textinput').value;
var listItem = document.createElement("li");
var checkbox = document.createElement("input")
checkbox.type = "checkbox";
listItem.appendChild(checkbox);
var itemText = document.createTextNode(todo);
listItem.appendChild(itemText);
document.getElementById('place').appendChild(listItem);

function changeColor(checkbox,itemText) {
var check = document.getElementById(checkbox);
var todoItem = document.getElementById(itemText);
if (check.checked == true) {
todoItem.style.backgroundColor="Red";
}
}
}



<title>ToDo</title>

<body>
<div id="container">
<div id="todoList">
<div id="textboxBackground">
<input type='text' id='textinput' placeholder='What do you need to do today?' />
<button type='button' id="myButton" class='button' onclick='todoadd()' value='Add to list' />Add To-do</button>
</div>
<ul id="place"></ul>
</div>






Bootstrap 3 forms inline checkboxes with input fields in same row

I have a rather large form I am creating using BS3 that has checkboxes and input fields in the same row. As you can see it makes a mess in terms of spacing. The rows with all checkboxes are very close together vertically and the rows with both checkboxes and input fields are further apart vertically. I would like to either make the spacing of the rows with checkboxes larger or shrink the spacing between the rows that have both. Any thoughts would be welcome. Here is the html -



<form>
<div class="row">
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Following Directions -</b>
</label>
<label class="checkbox-inline">
<input type="checkbox"> Routine
</label>
<label class="checkbox-inline">
<input type="checkbox"> Single-Step
</label>
<label class="checkbox-inline">
<input type="checkbox"> Novel
</label>
<label class="checkbox-inline">
<input type="checkbox"> Multi-Step
</label>
</div>
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Understanding Language Concept/Attributes</b>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Identifying Vocabulary -</b>
</label>
<label class="checkbox-inline">
<input type="checkbox"> Nouns
</label>
<label class="checkbox-inline">
<input type="checkbox"> Actions
</label>
<label class="checkbox-inline">
<input type="checkbox"> Novel
</label>
<label class="checkbox-inline">
<input type="checkbox"> Attributes
</label>
</div>
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Working Memory</b>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Recalling Verbal Information</b>
</label>
</div>
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Processing Speed</b>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<label class="checkbox-inline">
<input type="checkbox"> <b>Other -</b>
</label>
<label class="form-inline">
<textarea class="form-control input-sm" rows="1"></textarea>
</label>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Length of utterance/Expressive vocabulary</b>
</label>
</div>
<div class="col-sm-6">
<label class="form-inline">
Length of Utterance: <input type="text" class="form-control input-sm" id="">
</label>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Not using conventional gestures</b> (Pushing away, pointing, etc.)
</label>
</div>
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Use of grammatical structures -</b>
</label>
<label class="form-inline">
Which Ones? <input type="text" class="form-control input-sm" id="" >
</label>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Word Retrieval</b>
</label>
</div>
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Telling story in sequence/providing relevant details</b>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Answering Questions -</b>
</label>
<label class="checkbox-inline">
<input type="checkbox"> Yes/No
</label>
<label class="checkbox-inline">
<input type="checkbox"> WH Questions
</label>
<label class="checkbox-inline">
<input type="checkbox"> Asking Questions
</label>
</div>
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox"> <b>Other -</b>
</label>
<label class="form-inline">
<textarea class="form-control input-sm" rows="1"></textarea>
</label>
</div>
</div>
</form>




Is it possible to convert the following jquery to css?

I have the following snippet:





$(".status").on("click", function() {
if ($(this).prop("checked")) {
$(this).next().show();
} else {
$(this).next().hide();
}
});



<script src="http://ift.tt/1oMJErh"></script>

<div class="info">
<input type="checkbox" class="status" checked />
<div class="infoCont">....lot of stuff......</div>
</div>
<div class="info">
<input type="checkbox" class="status" checked />
<div class="infoCont">....lot of stuff......</div>
</div>



I achieved this result using jQuery but I want to ask if it is possible to achieve the same using pure css.


Thanks in advance.





Handling checkboxes in MVC controller

I have a html form to login, which contains amongst other inputs a checkbox for the "Remember me" function. For the other textboxes, I've been letting MVC match them up automatically (probably a word for that). So for textboxes I'd do "string [textboxname]" as a parameter, and that all works fine. I thought for a checkbox I could just do "bool [checkboxname]" but that does not work. Here is my form in the view:



@using (Html.BeginForm("login", "accounts"))
{
@Html.TextBox("email_username", null, new { @class = "textbox login email", placeholder = "Email or Username" });
@Html.TextBox("password", null, new { @class = "textbox login password", placeholder = "Password", type = "password" });
@Html.CheckBox("remember_me", new { @class = "checkbox remember-me" });
<input type="submit" value="Login" class="button login" />
}


And my controller action that handles the form submission:



[HttpPost]
public ActionResult Login(string email_username, string password, bool remember_me)
{
//Do things
}


What would be the best way to go about handling this?