lundi 2 avril 2018

Choosing a set of items and another set of items for every selected item of the first list (HTML + jQuery)

I have a list of shows, with each show there are associated several seances.

I need to select a subset of shows. For every selected (that is being in this subset) show I need to select a subset of its seances, in order that I could be able to select the list of seances associated with the show.

The best solution I have come up is the following:

  • display the list of shows as a <select multiple> widget (wrapped in a jquery.multiselect.min.js wrapper);
  • at the right of it display a <select> widget with the list of all shows selected in the previous widget;
  • at the right of the list of selected shows display (using dynamic loading list of seances with AJAX) a <select multiple> widget (wrapped in a jquery.multiselect.min.js wrapper) with the list of seances for the show selected in the previous widget.

I ask about what are alternatives to the above solution.




AngularJS, better way to subtotalize items from ng-repeat

I'm doing a table and totalizing all the items, but now I'm trying to get the value from some line only, I'm from Jquery and I'm thinking like Jquery apps, there a good way to do this in AngularJS?

I put a IMG to explain the situation.

Some advice?

enter image description here




jquery - check/uncheck customized checkbox with hidden input

I have this in HTML

<div class="my-checkbox">
    <label>I do agree</label>
    <input type="hidden" name="agreement" value="0">
</div>

and this in jQuery

$('.my-checkbox').on('click', function()
{
    if($(this).children('[type="hidden"]').val() == 0)
    {
        $(this).children('[type="hidden"]').val(0);
        $(this).removeClass('active');
    }
    else
    {
        $(this).children('[type="hidden"]').val(1);
        $(this).addClass('active');
    }
});

When I click .my-checkbox, it will change the value to 1 and add class active and when I click it again vice-versa. It works correctly but in mobile device when I click it it changes the value and set to active but when I click it again, it changes the value but the active class doesn't remove. How do I know that? just by double clicking and submit the form and the result was => you should agree with agreements.

Thanks




How to make check box in each row selected by default in Vaadin table?

I am new to Vaddin. How to make check box in each row selected by default in Vaadin table? I have gone through some Vaadin example, which specifies by writing "field.setValue(true)" will make check boxes in each row selected. But the solution is not working for me. Kindly help me to find out where I am going wrong with below code. Here I have used DefaultFieldFactory to generate fields for each row.

public class ReviewTimesheetTable extends ViewComponent {

private Map<ReviewTimesheetTableDto, HashMap<String, AbstractField<?>>> tableItem = new HashMap<ReviewTimesheetTableDto, HashMap<String, AbstractField<?>>>();
BeanItemContainer<ReviewTimesheetTableDto> data = new BeanItemContainer<ReviewTimesheetTableDto>(
        ReviewTimesheetTableDto.class);
private Table table;

public void init() {
    // Create a data source and bind it to a table
    table = new Table("", data);
    table.addStyleName("generateColumnTable");
    table.setWidth("100%");
    table.setPageLength(table.getItemIds().size());
    table.setVisibleColumns(new Object[] { "chkBox", "taskDate", "employeeId", "taskId", "crJiraId",
            "taskDesc","hour","minute"/*, "Delete" */});

    table.setColumnHeader("chkBox", "Select");
    table.setColumnHeader("taskDate", "Task Date");
    table.setColumnHeader("employeeId", "Employee ID");
    table.setColumnHeader("taskId", "Task ID");
    table.setColumnHeader("crJiraId", "Subtask ID");
    table.setColumnHeader("taskDesc", "Task Description");
    table.setColumnHeader("hour", "Hour");
    table.setColumnHeader("minute", "Minute");

    table.setEditable(true);

    table.setTableFieldFactory(new ImmediateFieldFactory());
}
public class ImmediateFieldFactory extends DefaultFieldFactory {

    @Override
    public Field<?> createField(Container container, Object itemId,
            Object propertyId, Component uiContext) {
        final ReviewTimesheetTableDto timesheetDetail = (ReviewTimesheetTableDto) itemId;

        Map<String, AbstractField<?>> tableRow = null;

        if(tableItem.get(timesheetDetail) == null)
        {
            tableItem.put(timesheetDetail,
                    new HashMap<String, AbstractField<?>>());

        }
        tableRow = tableItem.get(timesheetDetail);

        if ("taskId".equals(propertyId)) {
            GComboBox box = new GComboBox();
            tableRow.put("taskId", box);
            setTaskValues(box, timesheetDetail);
            //addTaskListener(box);
            box.setData(timesheetDetail);
            if(timesheetDetail != null && timesheetDetail.getTaskId() != null) {
                box.setDescription(timesheetDetail.getTaskId().getValue());
            }
            if(isSubmit){
                box.setReadOnly(true);
            }

            if(timesheetDetail.getIsAdd() != null && timesheetDetail.getIsAdd()){
                box.setReadOnly(false);
            }
            return box;
        }else if ("crJiraId".equals(propertyId)) {
            TextField field = new TextField();
            field.setEnabled(true);
            field.setWidth("200px");
            field.setNullRepresentation("");
            if(isSubmit){
                field.setReadOnly(true);
            }
            if(timesheetDetail.getIsAdd() != null && timesheetDetail.getIsAdd()){
                field.setReadOnly(false);
            }
            field.setMaxLength(50);

            field.setDescription(timesheetDetail.getCrJiraId());
            tableRow.put("crJiraId", field);
            return field;
        }else if ("taskDesc".equals(propertyId)) {
            TextField field = new TextField();
            field.setEnabled(true);
            field.setWidth("300px");
            field.setNullRepresentation("");
            field.setReadOnly(false);
            tableRow.put("taskDesc", field);
            field.setMaxLength(2000);
            field.setData(timesheetDetail);
            addDetailPopupForTaskDesc(field, null);

            if(timesheetDetail.getTaskDesc() != null){
                field.setDescription(timesheetDetail.getTaskDesc());
            }
            field.setReadOnly(true);
            if(timesheetDetail.getIsAdd() != null && timesheetDetail.getIsAdd()){
                field.setReadOnly(false);
            }
            return field;
        }else if ("hour".equals(propertyId)) {
            GComboBox box = new GComboBox();
            box.setWidth("60px");
            tableRow.put("hour", box);
            box.addValueChangeListener(addHourListener(box));
            setHourValues(box, timesheetDetail);
            box.setData(timesheetDetail);
            if(isSubmit){
                box.setReadOnly(true);
            }
            if(timesheetDetail.getIsAdd() != null && timesheetDetail.getIsAdd()){
                box.setReadOnly(false);
            }
            return box;
        }else if ("minute".equals(propertyId)) {
            GComboBox box = new GComboBox();
            box.setWidth("80px");
            tableRow.put("minute", box);
            box.addValueChangeListener(addMinuteListener(box));
            setMinuteValues(box, timesheetDetail);
            box.setData(timesheetDetail);
            if(isSubmit){
                box.setReadOnly(true);
            }
            if(timesheetDetail.getIsAdd() != null && timesheetDetail.getIsAdd()){
                box.setReadOnly(false);
            }
            return box;
        }else if ("employeeId".equals(propertyId)) {
            /*TextField field = new TextField();
            field.setEnabled(true);
            field.setWidth("100%");
            field.setNullRepresentation("");
            field.setReadOnly(true);
            field.setMaxLength(50);
            field.setDescription(timesheetDetail.getEmpId());
            tableRow.put("empId", field);
            return field;*/

            GComboBox box = new GComboBox();
            tableRow.put("employeeId", box);
            setEmpValues(box, timesheetDetail);
            box.setData(timesheetDetail);
            if(timesheetDetail != null && timesheetDetail.getEmployeeId() != null) {
                box.setDescription(timesheetDetail.getEmployeeId().getValue());
            }
            if(isSubmit){
                box.setReadOnly(true);
            }
            if(timesheetDetail.getIsAdd() != null && timesheetDetail.getIsAdd()){
                box.setReadOnly(false);
            }
            /*if(timesheetDetail.getIsAdd() != null && timesheetDetail.getIsAdd()){
                box.setReadOnly(false);
            }*/
            return box;
        }else if ("taskDate".equals(propertyId)) {
            DateField field = new DateField();
            field.setEnabled(true);
            field.setWidth("110px");
            field.setReadOnly(true);
            if(timesheetDetail.getIsAdd() != null && timesheetDetail.getIsAdd()){
                field.setReadOnly(false);
            }
            field.setDateFormat("dd-MM-yyyy");

            tableRow.put("taskDate", field);
            return field;
        }else if ("chkBox".equals(propertyId)) {
            CheckBox field = new CheckBox();
            field.setEnabled(true);
            field.setWidth("30px");
            field.setDescription(SHAConstants.SELECT);

            **field.setValue(true);**

            tableRow.put("chkBox", field);
            return field;
        }else {
            Field<?> field = super.createField(container, itemId,
                    propertyId, uiContext);

            if (field instanceof TextField)
                field.setWidth("100%");
            field.setEnabled(true);
            return field;
        }
    }
}

Your contribution will be very much helpful. Thanks in advance. Kindly find Output of above code below. Output of above code below




dimanche 1 avril 2018

How to use a dictionary to create tkinter check boxes, then check which are ticked

I am trying to create a menu program in tkinter, where check boxes are created from items in a dictionary, then the total price of selected items is calculated when a button is clicked.

menu_items = {"Spam - £3" : 3, "Eggs - £7" : 7, "Chips - £1" : 1, "Beer - £2" : 2}

def widgets(self):
    # create menu list
    row = 1
    for item in menu_items:
        self.item = BooleanVar()
        Checkbutton(self,
                    text = item,
                    variable = self.item
                    ).grid(row = row, column = 0, sticky = W)
        row += 1

    calc_but = Button(self,
                      text = "Click to calculate",
                      command = self.calculate
                      ).grid(row = row + 1, column = 0, sticky = W)

    self.results_txt = Text(self, width = 20, height = 4, wrap = WORD)
    self.results_txt.grid(row = row + 2, column = 0, columnspan = 2)

This creates check boxes, button and text display just fine, but my problem comes with my calculate method.

def calculate(self):
    bill = 0
    for item in menu_items:
        if self.item.get():
            bill += menu_items.get(item)               

    msg = "Total cost - £" + str(bill)       
    self.results_txt.delete(0.0, END)
    self.results_txt.insert(0.0, msg)

It will add up everything (ticked or not), but only when the final check box is ticked. It displays 0 if the final item is not ticked.

I am not sure what my problem is, or if I am approaching this in the wrong way.




How do I make a checkbox which if it isn't checked, the user cannot submit an answer (move forward) android

I have a submit answers button which I don't want to execute unless a checkbox is checked. Anyone know how I could do that?




How to check if a checkbox inside a spinner is checked? [Android Studio]

So, I do have a MainActivity were inside there is a spinner

Java code:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final boolean[] selected_action = {false, false, false};

        final String[] select_action = {"Select the option(s)",
                "WhatsApp backup databases", "Images Miniature", "Caches"};
        Spinner spinner = (Spinner) findViewById(R.id.spinner);

        ArrayList<StateVO> listVOs = new ArrayList<>();

        for (String aSelect_action : select_action) {
            StateVO stateVO = new StateVO();
            stateVO.setTitle(aSelect_action);
            stateVO.setSelected(stateVO.isSelected());
            listVOs.add(stateVO);
        }

        MyAdapter myAdapter = new MyAdapter(MainActivity.this, 0, listVOs);

        spinner.setAdapter(myAdapter);

        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                for (int i = 0; i < selected_action.length; i++) {

                    if (selected_action[i]) {

                        Toast.makeText(MainActivity.this, "True", Toast.LENGTH_SHORT).show();

                    }

                }

            }
        });

    }

}

And here it is the XML code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.lorenzomoscati.remover.MainActivity">

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="164dp" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="61dp"
        android:text="@string/start" />

</RelativeLayout>

Cool, then I've made a StateVO.java for the spinner as well as a custom adapter called MyAdapter.java.

StateVO.java:

public class StateVO {
    private String title;
    private boolean selected;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    boolean isSelected() {
        return selected;
    }

    void setSelected(boolean selected) {
        this.selected = selected;
    }

}

MyAdapter.java:

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.CompoundButton;

import java.util.ArrayList;
import java.util.List;

public class MyAdapter extends ArrayAdapter<StateVO> {
    private Context mContext;
    private ArrayList<StateVO> listState;
    private MyAdapter myAdapter;
    private boolean isFromView = false;

    public MyAdapter(Context context, int resource, List<StateVO> objects) {
        super(context, resource, objects);
        this.mContext = context;
        this.listState = (ArrayList<StateVO>) objects;
        this.myAdapter = this;
    }

    @Override
    public View getDropDownView(int position, View convertView,
                                ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    public View getCustomView(final int position, View convertView,
                              ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null) {
            LayoutInflater layoutInflater = LayoutInflater.from(mContext);
            convertView = layoutInflater.inflate(R.layout.spinner_item, null);
            holder = new ViewHolder();
            holder.mTextView = (TextView) convertView
                    .findViewById(R.id.text);
            holder.mCheckBox = (CheckBox) convertView
                    .findViewById(R.id.checkbox);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mTextView.setText(listState.get(position).getTitle());

        isFromView = true;
        holder.mCheckBox.setChecked(listState.get(position).isSelected());
        isFromView = false;

        if ((position == 0)) {
            holder.mCheckBox.setVisibility(View.INVISIBLE);
        } else {
            holder.mCheckBox.setVisibility(View.VISIBLE);
        }
        holder.mCheckBox.setTag(position);
        holder.mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                int getPosition = (Integer) buttonView.getTag();

            }
        });
        return convertView;


    }

    private class ViewHolder {
        private TextView mTextView;
        private CheckBox mCheckBox;
    }
}

So the problem is the following: How do I get checked if the checkboxes inside the spinner are checked or nor? In which file do I have to put the checking code? What should be like the checking code?

I've tried a lot (OnClick for example), but I didn't get so far. Probably because I implemented the code in a wrong way. I'd be glad if anyone can help.