> For the complete documentation index, see [llms.txt](https://docs.wem.io/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wem.io/platform/tutorials/building-widgets/wemscript/8-types/3-conceptset.md).

# 3. ConceptSet

A `conceptset` type holds a set of items of type `concept`. This `conceptset` has no predefined range and accepts any `concept`, which distinguishes it from a concept data field that does have a range.

```wemscript
<?
    var @cs: conceptset

    /* Assign the concept set with a single concept from @ConceptProperty1 */
    @cs := @ConceptProperty1
    
    /* Loop through the range of the concept set data field */
    loop range of @ConceptSetProperty
        /* Add the current concept from the range to the concept set @cs */
        @cs := @cs + concept
    end

    /* Remove @ConceptProperty2 from the concept set @cs */
    @cs := @cs - @ConceptProperty2

    /* Loop through the concepts included in the concept set of @ConceptSetProperty */
    loop @ConceptSetProperty
        /* ... */
    end
?>
```

#### Checkbox List Example

```html
<? register input @ConceptSetProperty ?>
<? var @id := OutputId(@ConceptSetProperty) ?>
<? loop range of @ConceptSetProperty ?>
	<label>
		<input 
			type="checkbox" 
			name="<?attr @id ?>" <? if @ConceptSetProperty contains concept ?>checked<? end ?>
			value="<?attr ConceptId(concept) ?>"
		>
		<?= concept ?>
	</label>
<? end ?>
```

In this example, we `register input` for our `@ConceptSetProperty`, and we store the output ID in a variable called `@id`. This is important because all checkboxes must share the same name according to HTML specifications. Next, we `loop` through the `range of @ConceptSetProperty` to generate the checkboxes. We set the name to `@id`, the value to `ConceptId(concept)`, and check if `@ConceptSetProperty contains concept`. If it does, we add the "checked" attribute to the checkbox. After rendering the checkbox input, we display the name of the concept using `<?= concept ?>`.

In the background, during a postback, we send back a list of IDs that will update the data model bound to `@ConceptSetProperty`.

#### Textbox Example

The following example demonstrates a less user-friendly UX for updating a concept set. However, it illustrates the concept of updating a concept data model with a postback using a single input field—in this case, a text field.

```wemscript
<? 
	register input @ConceptSetProperty
	
	var @ids: text
	
	loop range of @ConceptSetProperty 
?>
	<div>
		<? 
			var @included := @ConceptSetProperty contains concept
			
			if @included
				@ids := @ids + (if Length(@ids) <> 0 then "," else "") + ConceptId(concept)
			end
		?>
		<?= ConceptId(concept) ?>: <?= concept ?> <? if @included ?>(included)<? end ?>
	</div>
<? end ?>
<div>
    <input type="text" name="<?attr OutputId(@ConceptSetProperty) ?>" value="<?attr @ids ?>">
</div>
```

This widget renders all the concepts along with their concept IDs from the range of `@ConceptSetProperty`. When `@ConceptSetProperty contains concept`, that concept will be included in the value of the text field. The result will be a comma-separated list of IDs, e.g., `1,23,400`. To update the concept set, you simply modify the text value, which holds the IDs that are part of this concept set. Note that the format is very strict; for instance, the value `3,70,` with an additional trailing comma at the end is not accepted by the WEM runtime and will result in an empty concept set.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wem.io/platform/tutorials/building-widgets/wemscript/8-types/3-conceptset.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
