> For the complete documentation index, see [llms.txt](https://docs.ngsurvey.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ngsurvey.com/ar/form-management/form-designer/condition-rules/conditions-rules/javascript-conditions.md).

# شروط Javascript

## 👨‍💻️ ما هي شروط Javascript؟

باستخدام شروط javascript يمكنك تعريف قواعد الشروط باستخدام لغة Javascript. شروط javascript تمنحك الحرية بعيدًا عن الشروط المحددة مسبقًا التي يوفرها [قواعد شرطية ](/ar/form-management/form-designer/condition-rules/conditions-rules.md)واجهة المستخدم وتمنحك الحرية التامة لكتابة شروطك الخاصة باستخدام تعليمات ومشغلات Javascript الأصلية.

يجب أن يُرجع كود شرط javascript إما true إذا كان ينبغي تقييم قاعدة الشرط بنجاح أو false إذا فشل.

يمكنك استخدام كائنات الإعداد المسبق التالية في كودك

* **respondentAnswers** هي مصفوفة إجابات المستجيب الحالية.
* **languageCode** هي سلسلة اللغة المحددة حاليًا للمستجيب.
* **إجابات** هي مصفوفة الإجابات الحالية للاستبيان.,

```javascript
RespondentAnswer {
  answerId: string;
  respondentId: string;
  sectionNumber: number;
  value: string;
  disabled: boolean;
  authorizationToken: string;
}
```

```
 Answer {
  id: string;
  questionId: string;
  answerTypeId: string;
  text: string;
  pipeAlias:string;
  }
```

الكود التالي سيقوم بالتكرار عبر إجابات المستجيب الحالية والتحقق من أن الإجابة ذات المعرف "answerid1234" قد تم اختيارها من قبل المستجيب.

```javascript
for (var i=0;i<respondentAnswers.length;i++){
  if (respondentAnswers[i].answerId == 'answerid1234') {
     return true;
  }
}
return false;
```

يمكنك استخدام دالة المساعدة لتحديد السؤال / الإجابة للحصول على معرفات الأسئلة أو الإجابات

![](/files/6431d372b6325175aeef12a061748673f2efca5b)

{% hint style="info" %}
يمكنك استخدام **اختبار الكود** الزر لاختبار كودك باستخدام مجموعة فارغة من إجابات المستجيب.&#x20;
{% endhint %}

## 📚 دوال المساعدة

لتجنب كود طويل ومتكرر يمكنك أيضًا استخدام دوال المساعدة التالية.&#x20;

* **isAnswerAnswered(answerId, textValue)** ترجع true إذا تم اختيار الإجابة أو إدخالها من قبل المستجيب. يمكنك أيضًا تزويد وسيط textValue لمقارنة النص الذي أدخله المستجيب بنص معين.
* **isQuestionAnswered(questionId)** ستُرجع true إذا تم اختيار أو إدخال أي إجابات للسؤال.

العينة التالية تتحقق من أن الإجابة ذات المعرف "MCf35sd\_UXTarDERxRHa" لها قيمتها مضبوطة على ngSurvey.

```
return isAnswerAnswered('MCf35sd_UXTarDERxRHa', 'ngSurvey');
```

## ⚠️ قيود معروفة

يرجى الملاحظة أن هذه الميزة لديها حاليًا القيود التالية والتي يجب إزالتها في إصدار قادم.

* المحرك يدعم حاليًا فقط **ECMAScript 5.** لذا لا تستخدم أي تعليمات لغوية ليست مبنية على معايير ECMAScript 5.
* وبما أن شروط javascript تعمل أيضًا على جانب الخادم **لا تستخدم** أي **كائنات محددة بالمتصفح** مثل window, console إلخ.. لأنه لا يمكن تقييمها على جانب الخادم لعدم وجود متصفح هناك.
* إذا قمت بعمل نسخة من الاستبيان الخاص بك باستخدام [ميزة النسخ المتماثل](/ar/projects/create-survey.md) الميزات فستحتاج إلى إعادة تعيين معرفات الأسئلة والإجابات لشرط javascript يدويًا إلى المعرفات الجديدة المنشأة في الاستبيان المستنسخ.&#x20;

{% hint style="info" %}
إذا كنت بحاجة فعلاً لاستخدام كائنات المتصفح وأحدث تعليمات / مشغلات لغة Javascript يمكنك القيام بذلك عبر إيقاف التحقق على جانب الخادم في [خصائص الاستبيان الخاص بك](/ar/form-management/form-designer/form-settings.md). لاحظ أنه في مثل هذه الحالة لن يتم إجراء أي تحقق على جانب الخادم لضمان صحة معرفات السؤال / الإجابات في إجابات المستجيب. &#x20;
{% endhint %}


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.ngsurvey.com/ar/form-management/form-designer/condition-rules/conditions-rules/javascript-conditions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
